Skip to content

Commit add49a1

Browse files
committed
chore(transformer): Move overload tests into its own file nested under method
1 parent 3a051d2 commit add49a1

File tree

3 files changed

+79
-52
lines changed

3 files changed

+79
-52
lines changed

test/transformer/descriptor/methods/methods.test.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,6 @@ describe('for methods', () => {
5858
});
5959
});
6060

61-
describe('for interface call signature with overload', () => {
62-
interface InterfaceWithCallSignature {
63-
(a: number): number;
64-
(a: string): string;
65-
b: string;
66-
}
67-
68-
it('should only consider the first signature declaration', () => {
69-
const properties: InterfaceWithCallSignature = createMock<InterfaceWithCallSignature>();
70-
expect(properties(2)).toBe(0);
71-
// @ts-ignore
72-
expect(properties('2')).toBe(0);
73-
expect(properties.b).toBe('');
74-
});
75-
});
76-
7761
describe('for interface call signature with recursive', () => {
7862
interface InterfaceWithCallSignature<T> {
7963
(a: number): InterfaceWithCallSignature<T>;
@@ -99,12 +83,6 @@ describe('for methods', () => {
9983
b: string;
10084
}
10185

102-
interface InterfaceWithConstructSignatureOverload {
103-
new (a: number): { a: number };
104-
new (b: string): { b: string };
105-
new (): { c: Date };
106-
}
107-
10886
it('should set the constructor and properties', () => {
10987
const properties: InterfaceWithConstructSignature = createMock<InterfaceWithConstructSignature>();
11088
expect(new properties(2).a).toBe(0);
@@ -117,14 +95,6 @@ describe('for methods', () => {
11795
expect(new properties(2).b).toBe('');
11896
expect(properties.b).toBe('');
11997
});
120-
121-
it('should use the overload as requested by input', () => {
122-
const properties: InterfaceWithConstructSignatureOverload = createMock<InterfaceWithConstructSignatureOverload>();
123-
// eslint-disable-next-line
124-
expect((new properties(0)).a).toBe(0);
125-
expect((new properties('')).b).toBe('');
126-
expect((new properties()).c).toBeInstanceOf(Date);
127-
});
12898
});
12999

130100
describe('for interface construct signature', () => {
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { createMock } from 'ts-auto-mock';
2+
3+
import {
4+
exportedDeclaredOverloadedFunction,
5+
// ExportedDeclaredClass,
6+
} from '../utils/typeQuery/typeQueryUtils';
7+
8+
describe('for overloads', () => {
9+
10+
describe('for type query', () => {
11+
12+
it('should assign the correct function mock for literal inputs', () => {
13+
const functionMock: typeof exportedDeclaredOverloadedFunction = createMock<typeof exportedDeclaredOverloadedFunction>();
14+
15+
// eslint-disable-next-line
16+
const expectations = [
17+
['', 0, false],
18+
[false, '', 0],
19+
[0, false, ''],
20+
[false, false, false],
21+
[''],
22+
[false],
23+
[0],
24+
];
25+
26+
for (const args of expectations) {
27+
// eslint-disable-next-line
28+
const [first] = args;
29+
30+
// @ts-ignore
31+
expect(functionMock(...args)).toEqual(first);
32+
}
33+
});
34+
35+
// FIXME: Support more than just literals
36+
// it('should assign the correct function mock for mockable inputs', () => {
37+
// const classMock: typeof ExportedDeclaredClass = createMock<typeof ExportedDeclaredClass>();
38+
39+
// const functionMock: typeof exportedDeclaredOverloadedFunction = createMock<typeof exportedDeclaredOverloadedFunction>();
40+
41+
// expect(functionMock(new classMock())).toBeInstanceOf(ExportedDeclaredClass);
42+
// });
43+
44+
});
45+
46+
describe('for interface', () => {
47+
describe('for construct signature', () => {
48+
interface InterfaceWithConstructSignatureOverload {
49+
new (a: number): { a: number };
50+
new (b: string): { b: string };
51+
new (): { c: Date };
52+
}
53+
54+
it('should use the correct signature as requested by input', () => {
55+
const properties: InterfaceWithConstructSignatureOverload = createMock<InterfaceWithConstructSignatureOverload>();
56+
expect((new properties(0)).a).toBe(0);
57+
expect((new properties('')).b).toBe('');
58+
// FIXME: Enable after Date PR
59+
// expect((new properties()).c).toBeInstanceOf(Date);
60+
});
61+
});
62+
});
63+
64+
describe('call signature', () => {
65+
interface InterfaceWithCallSignature {
66+
(a: number): number;
67+
(a: string): string;
68+
b: string;
69+
}
70+
71+
it('should consider all signature declarations and properties', () => {
72+
const properties: InterfaceWithCallSignature = createMock<InterfaceWithCallSignature>();
73+
expect(properties(2)).toBe(0);
74+
expect(properties('2')).toBe('');
75+
expect(properties.b).toBe('');
76+
});
77+
});
78+
79+
});

test/transformer/descriptor/typeQuery/typeQuery.test.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
ExportedClass,
77
ExportedDeclaredClass,
88
exportedDeclaredFunction,
9-
exportedDeclaredOverloadedFunction,
109
ExportedEnum,
1110
exportedFunction,
1211
WrapExportedClass,
@@ -42,27 +41,6 @@ describe('typeQuery', () => {
4241
expect(functionMock()).toEqual('');
4342
});
4443

45-
it('should assign the correct function mock for an imported and overloaded function declaration', () => {
46-
const functionMock: typeof exportedDeclaredOverloadedFunction = createMock<typeof exportedDeclaredOverloadedFunction>();
47-
48-
// eslint-disable-next-line
49-
const expectations = [
50-
{ args: ['', 0, false], returnValue: '' },
51-
{ args: [false, '', 0], returnValue: false },
52-
{ args: [0, false, ''], returnValue: 0 },
53-
{ args: [false, false, false], returnValue: false },
54-
{ args: [''], returnValue: '' },
55-
{ args: [false], returnValue: false },
56-
{ args: [0], returnValue: 0 },
57-
];
58-
59-
for (const { args, returnValue } of expectations) {
60-
// eslint-disable-next-line
61-
const [first, second, third] = args;
62-
expect(functionMock(first, second, third)).toEqual(returnValue);
63-
}
64-
});
65-
6644
it('should assign the function mock for an imported function declaration with body', () => {
6745
const functionMock: typeof exportedFunction = createMock<typeof exportedFunction>();
6846

0 commit comments

Comments
 (0)