Skip to content

Commit e541e2b

Browse files
ulrichsgffMathy
authored andcommitted
Change inference order for ObjectSubstituteTransformation. Fixes #24. (#56)
1 parent f67cf2f commit e541e2b

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

spec/issues/24.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import test from 'ava';
2+
3+
import { Substitute } from '../../src/index';
4+
5+
interface IHaveOptionalArguments {
6+
onlyOptional(a?: number): number;
7+
mandatoryAndOptional(a: number, b?: number): number;
8+
}
9+
test('issue 24 - Mocked method arguments not allowed when verifying method was called', async t => {
10+
const substitute = Substitute.for<IHaveOptionalArguments>();
11+
substitute.onlyOptional().returns(1);
12+
substitute.onlyOptional(2).returns(2);
13+
14+
t.is(substitute.onlyOptional(), 1);
15+
t.is(substitute.onlyOptional(2), 2);
16+
17+
substitute.mandatoryAndOptional(1).returns(1);
18+
substitute.mandatoryAndOptional(1, 2).returns(2);
19+
20+
t.is(substitute.mandatoryAndOptional(1), 1);
21+
t.is(substitute.mandatoryAndOptional(1, 2), 2);
22+
});

src/Transformations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ type TerminatingObject<T> = {
3636

3737
type ObjectSubstituteTransformation<T extends Object> = {
3838
[P in keyof T]:
39-
T[P] extends () => infer R ? NoArgumentFunctionSubstitute<R> :
4039
T[P] extends (...args: infer F) => infer R ? FunctionSubstitute<F, R> :
40+
T[P] extends () => infer R ? NoArgumentFunctionSubstitute<R> :
4141
PropertySubstitute<T[P]>;
4242
}
4343

4444
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
4545

4646
export type OmitProxyMethods<T extends any> = Omit<T, 'mimick'|'received'|'didNotReceive'>;
4747

48-
export type DisabledSubstituteObject<T> = T extends ObjectSubstitute<OmitProxyMethods<infer K>, infer K> ? K : never;
48+
export type DisabledSubstituteObject<T> = T extends ObjectSubstitute<OmitProxyMethods<infer K>, infer K> ? K : never;

0 commit comments

Comments
 (0)