Skip to content

Commit b7ae0b8

Browse files
authored
chore: migrate type tests to TSTyche 2 (#15088)
1 parent 0d222c1 commit b7ae0b8

File tree

20 files changed

+431
-449
lines changed

20 files changed

+431
-449
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"strip-json-comments": "^3.1.1",
7979
"tempy": "^1.0.0",
8080
"ts-node": "^10.5.0",
81-
"tstyche": "^2.0.0-beta.0",
81+
"tstyche": "^2.0.0-beta.1",
8282
"typescript": "^5.0.4",
8383
"webpack": "^5.68.0",
8484
"webpack-node-externals": "^3.0.0",

packages/expect-utils/__typetests__/utils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ test('isA', () => {
2727
}
2828

2929
if (isA<Map<unknown, unknown>>('Map', sample)) {
30-
expect(sample).type.toEqual<Map<unknown, unknown>>();
30+
expect(sample).type.toBe<Map<unknown, unknown>>();
3131
}
3232

3333
if (isA<Set<unknown>>('Set', sample)) {
34-
expect(sample).type.toEqual<Set<unknown>>();
34+
expect(sample).type.toBe<Set<unknown>>();
3535
}
3636
});

packages/expect/__typetests__/expect.test.ts

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ describe('Expect', () => {
4343
const tester1: Tester = function (a, b, customTesters) {
4444
expect(a).type.toBeAny();
4545
expect(b).type.toBeAny();
46-
expect(customTesters).type.toEqual<Array<Tester>>();
47-
expect(this).type.toEqual<TesterContext>();
48-
expect(this.equals).type.toEqual<EqualsFunction>();
46+
expect(customTesters).type.toBe<Array<Tester>>();
47+
expect(this).type.toBe<TesterContext>();
48+
expect(this.equals).type.toBe<EqualsFunction>();
4949

5050
return undefined;
5151
};
@@ -57,7 +57,7 @@ describe('Expect', () => {
5757
(a, b, customTesters) => {
5858
expect(a).type.toBeAny();
5959
expect(b).type.toBeAny();
60-
expect(customTesters).type.toEqual<Array<Tester>>();
60+
expect(customTesters).type.toBe<Array<Tester>>();
6161
expect(this).type.toBeUndefined();
6262

6363
return true;
@@ -66,9 +66,9 @@ describe('Expect', () => {
6666
function anotherTester(a, b, customTesters) {
6767
expect(a).type.toBeAny();
6868
expect(b).type.toBeAny();
69-
expect(customTesters).type.toEqual<Array<Tester>>();
70-
expect(this).type.toEqual<TesterContext>();
71-
expect(this.equals).type.toEqual<EqualsFunction>();
69+
expect(customTesters).type.toBe<Array<Tester>>();
70+
expect(this).type.toBe<TesterContext>();
71+
expect(this.equals).type.toBe<EqualsFunction>();
7272

7373
return undefined;
7474
},
@@ -87,26 +87,26 @@ describe('Expect', () => {
8787
// TODO `actual` should be allowed to have only `unknown` type
8888
toBeWithinRange(actual: number, floor: number, ceiling: number) {
8989
expect(this.assertionCalls).type.toBeNumber();
90-
expect(this.currentTestName).type.toEqual<string | undefined>();
91-
expect(this.customTesters).type.toEqual<Array<Tester>>();
92-
expect(this.dontThrow).type.toEqual<() => void>();
93-
expect(this.error).type.toEqual<Error | undefined>();
94-
expect(this.equals).type.toEqual<EqualsFunction>();
95-
expect(this.expand).type.toEqual<boolean | undefined>();
96-
expect(this.expectedAssertionsNumber).type.toEqual<number | null>();
97-
expect(this.expectedAssertionsNumberError).type.toEqual<
90+
expect(this.currentTestName).type.toBe<string | undefined>();
91+
expect(this.customTesters).type.toBe<Array<Tester>>();
92+
expect(this.dontThrow).type.toBe<() => void>();
93+
expect(this.error).type.toBe<Error | undefined>();
94+
expect(this.equals).type.toBe<EqualsFunction>();
95+
expect(this.expand).type.toBe<boolean | undefined>();
96+
expect(this.expectedAssertionsNumber).type.toBe<number | null>();
97+
expect(this.expectedAssertionsNumberError).type.toBe<
9898
Error | undefined
9999
>();
100100
expect(this.isExpectingAssertions).type.toBeBoolean();
101-
expect(this.isExpectingAssertionsError).type.toEqual<
101+
expect(this.isExpectingAssertionsError).type.toBe<
102102
Error | undefined
103103
>();
104-
expect(this.isNot).type.toEqual<boolean | undefined>();
104+
expect(this.isNot).type.toBe<boolean | undefined>();
105105
expect(this.numPassingAsserts).type.toBeNumber();
106-
expect(this.promise).type.toEqual<string | undefined>();
107-
expect(this.suppressedErrors).type.toEqual<Array<Error>>();
108-
expect(this.testPath).type.toEqual<string | undefined>();
109-
expect(this.utils).type.toEqual<MatcherUtils>();
106+
expect(this.promise).type.toBe<string | undefined>();
107+
expect(this.suppressedErrors).type.toBe<Array<Error>>();
108+
expect(this.testPath).type.toBe<string | undefined>();
109+
expect(this.utils).type.toBe<MatcherUtils>();
110110

111111
const pass = actual >= floor && actual <= ceiling;
112112
if (pass) {
@@ -162,7 +162,7 @@ describe('MatcherFunction', () => {
162162
};
163163
};
164164

165-
expect<ToBeWithinRange>().type.toBeAssignable(toBeWithinRange);
165+
expect<ToBeWithinRange>().type.toBeAssignableWith(toBeWithinRange);
166166
});
167167

168168
test('requires the `actual` argument to be of type `unknown`', () => {
@@ -173,7 +173,7 @@ describe('MatcherFunction', () => {
173173
};
174174
};
175175

176-
expect<MatcherFunction>().type.not.toBeAssignable(actualMustBeUnknown);
176+
expect<MatcherFunction>().type.not.toBeAssignableWith(actualMustBeUnknown);
177177
});
178178

179179
test('allows omitting the `expected` argument', () => {
@@ -193,7 +193,9 @@ describe('MatcherFunction', () => {
193193
};
194194
};
195195

196-
expect<AllowOmittingExpected>().type.toBeAssignable(allowOmittingExpected);
196+
expect<AllowOmittingExpected>().type.toBeAssignableWith(
197+
allowOmittingExpected,
198+
);
197199
});
198200

199201
test('the `message` property is required in the return type', () => {
@@ -203,7 +205,7 @@ describe('MatcherFunction', () => {
203205
};
204206
};
205207

206-
expect<MatcherFunction>().type.not.toBeAssignable(lacksMessage);
208+
expect<MatcherFunction>().type.not.toBeAssignableWith(lacksMessage);
207209
});
208210

209211
test('the `pass` property is required in the return type', () => {
@@ -213,15 +215,15 @@ describe('MatcherFunction', () => {
213215
};
214216
};
215217

216-
expect<MatcherFunction>().type.not.toBeAssignable(lacksPass);
218+
expect<MatcherFunction>().type.not.toBeAssignableWith(lacksPass);
217219
});
218220

219221
test('context is defined inside a matcher function', () => {
220222
const toHaveContext: MatcherFunction = function (
221223
actual: unknown,
222224
...expected: Array<unknown>
223225
) {
224-
expect(this).type.toEqual<MatcherContext>();
226+
expect(this).type.toBe<MatcherContext>();
225227

226228
if (expected.length > 0) {
227229
throw new Error('This matcher does not take any expected argument.');
@@ -243,7 +245,7 @@ describe('MatcherFunction', () => {
243245
actual: unknown,
244246
...expected: Array<unknown>
245247
) {
246-
expect(this).type.toEqual<CustomContext>();
248+
expect(this).type.toBe<CustomContext>();
247249
expect(this.customMethod()).type.toBeVoid();
248250

249251
if (expected.length > 0) {
@@ -272,7 +274,7 @@ describe('MatcherFunction', () => {
272274
CustomContext,
273275
[count: number]
274276
> = function (actual: unknown, count: unknown) {
275-
expect(this).type.toEqual<CustomContext>();
277+
expect(this).type.toBe<CustomContext>();
276278
expect(this.customMethod()).type.toBeVoid();
277279

278280
return {
@@ -281,7 +283,7 @@ describe('MatcherFunction', () => {
281283
};
282284
};
283285

284-
expect<CustomStateAndExpected>().type.toBeAssignable(
286+
expect<CustomStateAndExpected>().type.toBeAssignableWith(
285287
customContextAndExpected,
286288
);
287289
});

packages/jest-cli/__typetests__/jest-cli.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ import type {Options} from 'yargs';
1010
import {yargsOptions} from 'jest-cli';
1111

1212
test('yargsOptions', () => {
13-
expect(yargsOptions).type.toEqual<{[key: string]: Options}>();
13+
expect(yargsOptions).type.toBe<{[key: string]: Options}>();
1414
});

packages/jest-mock/__typetests__/Mocked.test.ts

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ describe('Mocked', () => {
2323

2424
const MockSomeClass = SomeClass as Mocked<typeof SomeClass>;
2525

26-
expect(MockSomeClass.mock.calls[0]).type.toEqual<
26+
expect(MockSomeClass.mock.calls[0]).type.toBe<
2727
[one: string, two?: boolean]
2828
>();
2929

30-
expect(MockSomeClass.prototype.methodA.mock.calls[0]).type.toEqual<[]>();
31-
expect(MockSomeClass.prototype.methodB.mock.calls[0]).type.toEqual<
30+
expect(MockSomeClass.prototype.methodA.mock.calls[0]).type.toBe<[]>();
31+
expect(MockSomeClass.prototype.methodB.mock.calls[0]).type.toBe<
3232
[a: string, b?: number]
3333
>();
3434

@@ -43,19 +43,19 @@ describe('Mocked', () => {
4343
),
4444
).type.toRaiseError();
4545

46-
expect(MockSomeClass.mock.instances[0].methodA.mock.calls[0]).type.toEqual<
46+
expect(MockSomeClass.mock.instances[0].methodA.mock.calls[0]).type.toBe<
4747
[]
4848
>();
49-
expect(MockSomeClass.prototype.methodB.mock.calls[0]).type.toEqual<
49+
expect(MockSomeClass.prototype.methodB.mock.calls[0]).type.toBe<
5050
[a: string, b?: number]
5151
>();
5252

5353
const mockSomeInstance = new MockSomeClass('a') as Mocked<
5454
InstanceType<typeof MockSomeClass>
5555
>;
5656

57-
expect(mockSomeInstance.methodA.mock.calls[0]).type.toEqual<[]>();
58-
expect(mockSomeInstance.methodB.mock.calls[0]).type.toEqual<
57+
expect(mockSomeInstance.methodA.mock.calls[0]).type.toBe<[]>();
58+
expect(mockSomeInstance.methodB.mock.calls[0]).type.toBe<
5959
[a: string, b?: number]
6060
>();
6161

@@ -68,7 +68,7 @@ describe('Mocked', () => {
6868
}),
6969
).type.toRaiseError();
7070

71-
expect(new SomeClass('sample')).type.toBeAssignable(mockSomeInstance);
71+
expect(new SomeClass('sample')).type.toBeAssignableWith(mockSomeInstance);
7272
});
7373

7474
test('wraps a function type with type definitions of the Jest mock function', () => {
@@ -78,14 +78,14 @@ describe('Mocked', () => {
7878

7979
const mockFunction = someFunction as Mocked<typeof someFunction>;
8080

81-
expect(mockFunction.mock.calls[0]).type.toEqual<[a: string, b?: number]>();
81+
expect(mockFunction.mock.calls[0]).type.toBe<[a: string, b?: number]>();
8282

8383
expect(mockFunction.mockReturnValue(123)).type.toRaiseError();
8484
expect(
8585
mockFunction.mockImplementation((a: boolean, b?: number) => true),
8686
).type.toRaiseError();
8787

88-
expect(someFunction).type.toBeAssignable(mockFunction);
88+
expect(someFunction).type.toBeAssignableWith(mockFunction);
8989
});
9090

9191
test('wraps an async function type with type definitions of the Jest mock function', () => {
@@ -97,7 +97,7 @@ describe('Mocked', () => {
9797
typeof someAsyncFunction
9898
>;
9999

100-
expect(mockAsyncFunction.mock.calls[0]).type.toEqual<[Array<boolean>]>();
100+
expect(mockAsyncFunction.mock.calls[0]).type.toBe<[Array<boolean>]>();
101101

102102
expect(mockAsyncFunction.mockResolvedValue(123)).type.toRaiseError();
103103
expect(
@@ -106,7 +106,7 @@ describe('Mocked', () => {
106106
),
107107
).type.toRaiseError();
108108

109-
expect(someAsyncFunction).type.toBeAssignable(mockAsyncFunction);
109+
expect(someAsyncFunction).type.toBeAssignableWith(mockAsyncFunction);
110110
});
111111

112112
test('wraps a function object type with type definitions of the Jest mock function', () => {
@@ -126,7 +126,7 @@ describe('Mocked', () => {
126126
typeof someFunctionObject
127127
>;
128128

129-
expect(mockFunctionObject.mock.calls[0]).type.toEqual<
129+
expect(mockFunctionObject.mock.calls[0]).type.toBe<
130130
[a: number, b?: string]
131131
>();
132132

@@ -135,7 +135,7 @@ describe('Mocked', () => {
135135
mockFunctionObject.mockImplementation(() => true),
136136
).type.toRaiseError();
137137

138-
expect(mockFunctionObject.one.more.time.mock.calls[0]).type.toEqual<
138+
expect(mockFunctionObject.one.more.time.mock.calls[0]).type.toBe<
139139
[time: number]
140140
>();
141141

@@ -148,7 +148,7 @@ describe('Mocked', () => {
148148
}),
149149
).type.toRaiseError();
150150

151-
expect(someFunctionObject).type.toBeAssignable(mockFunctionObject);
151+
expect(someFunctionObject).type.toBeAssignableWith(mockFunctionObject);
152152
});
153153

154154
test('wraps an object type with type definitions of the Jest mock function', () => {
@@ -190,26 +190,24 @@ describe('Mocked', () => {
190190

191191
const mockObject = someObject as Mocked<typeof someObject>;
192192

193-
expect(mockObject.methodA.mock.calls[0]).type.toEqual<[]>();
194-
expect(mockObject.methodB.mock.calls[0]).type.toEqual<[b: string]>();
195-
expect(mockObject.methodC.mock.calls[0]).type.toEqual<[c: number]>();
193+
expect(mockObject.methodA.mock.calls[0]).type.toBe<[]>();
194+
expect(mockObject.methodB.mock.calls[0]).type.toBe<[b: string]>();
195+
expect(mockObject.methodC.mock.calls[0]).type.toBe<[c: number]>();
196196

197-
expect(mockObject.one.more.time.mock.calls[0]).type.toEqual<[t: number]>();
197+
expect(mockObject.one.more.time.mock.calls[0]).type.toBe<[t: number]>();
198198

199-
expect(mockObject.SomeClass.mock.calls[0]).type.toEqual<
199+
expect(mockObject.SomeClass.mock.calls[0]).type.toBe<
200200
[one: string, two?: boolean]
201201
>();
202-
expect(mockObject.SomeClass.prototype.methodA.mock.calls[0]).type.toEqual<
202+
expect(mockObject.SomeClass.prototype.methodA.mock.calls[0]).type.toBe<
203203
[]
204204
>();
205-
expect(mockObject.SomeClass.prototype.methodB.mock.calls[0]).type.toEqual<
205+
expect(mockObject.SomeClass.prototype.methodB.mock.calls[0]).type.toBe<
206206
[a: string, b?: number]
207207
>();
208208

209-
expect(mockObject.someClassInstance.methodA.mock.calls[0]).type.toEqual<
210-
[]
211-
>();
212-
expect(mockObject.someClassInstance.methodB.mock.calls[0]).type.toEqual<
209+
expect(mockObject.someClassInstance.methodA.mock.calls[0]).type.toBe<[]>();
210+
expect(mockObject.someClassInstance.methodB.mock.calls[0]).type.toBe<
213211
[a: string, b?: number]
214212
>();
215213

@@ -265,16 +263,16 @@ describe('Mocked', () => {
265263
),
266264
).type.toRaiseError();
267265

268-
expect(someObject).type.toBeAssignable(mockObject);
266+
expect(someObject).type.toBeAssignableWith(mockObject);
269267
});
270268

271269
test('wraps the global `console` object type with type definitions of the Jest mock function', () => {
272270
const mockConsole = console as Mocked<typeof console>;
273271

274-
expect(console.log).type.toBeAssignable(
272+
expect(console.log).type.toBeAssignableWith(
275273
mockConsole.log.mockImplementation(() => {}),
276274
);
277-
expect<MockInstance<typeof console.log>>().type.toBeAssignable(
275+
expect<MockInstance<typeof console.log>>().type.toBeAssignableWith(
278276
mockConsole.log.mockImplementation(() => {}),
279277
);
280278
});

packages/jest-mock/__typetests__/ModuleMocker.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,32 +48,32 @@ const moduleMocker = new ModuleMocker(globalThis);
4848
const exampleMetadata = moduleMocker.getMetadata(exampleModule);
4949

5050
test('getMetadata', () => {
51-
expect(exampleMetadata).type.toEqual<MockMetadata<
51+
expect(exampleMetadata).type.toBe<MockMetadata<
5252
typeof exampleModule
5353
> | null>();
5454
});
5555

5656
test('generateFromMetadata', () => {
5757
const exampleMock = moduleMocker.generateFromMetadata(exampleMetadata!);
5858

59-
expect(exampleMock).type.toEqual<Mocked<typeof exampleModule>>();
59+
expect(exampleMock).type.toBe<Mocked<typeof exampleModule>>();
6060

61-
expect(exampleMock.methodA.mock.calls).type.toEqual<
61+
expect(exampleMock.methodA.mock.calls).type.toBe<
6262
Array<[a: number, b: number]>
6363
>();
64-
expect(exampleMock.methodB.mock.calls).type.toEqual<
64+
expect(exampleMock.methodB.mock.calls).type.toBe<
6565
Array<[a: number, b: number]>
6666
>();
6767

68-
expect(exampleMock.instance.memberA).type.toEqual<Array<number>>();
69-
expect(exampleMock.instance.memberB.mock.calls).type.toEqual<Array<[]>>();
68+
expect(exampleMock.instance.memberA).type.toBe<Array<number>>();
69+
expect(exampleMock.instance.memberB.mock.calls).type.toBe<Array<[]>>();
7070

7171
expect(exampleMock.propertyA.one).type.toBeString();
72-
expect(exampleMock.propertyA.two.mock.calls).type.toEqual<Array<[]>>();
72+
expect(exampleMock.propertyA.two.mock.calls).type.toBe<Array<[]>>();
7373
expect(exampleMock.propertyA.three.nine).type.toBeNumber();
74-
expect(exampleMock.propertyA.three.ten).type.toEqual<Array<number>>();
74+
expect(exampleMock.propertyA.three.ten).type.toBe<Array<number>>();
7575

76-
expect(exampleMock.propertyB).type.toEqual<Array<number>>();
76+
expect(exampleMock.propertyB).type.toBe<Array<number>>();
7777
expect(exampleMock.propertyC).type.toBeNumber();
7878
expect(exampleMock.propertyD).type.toBeString();
7979
expect(exampleMock.propertyE).type.toBeBoolean();

0 commit comments

Comments
 (0)