Skip to content

Commit e23c5c7

Browse files
authored
chore: add typechecks for tests of expect-utils and jest-circus (#13387)
1 parent a905b13 commit e23c5c7

File tree

7 files changed

+18
-16
lines changed

7 files changed

+18
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"test": "yarn lint && yarn jest",
114114
"typecheck": "yarn typecheck:examples && yarn typecheck:tests",
115115
"typecheck:examples": "tsc -p examples/angular --noEmit && tsc -p examples/expect-extend --noEmit && tsc -p examples/typescript --noEmit",
116-
"typecheck:tests": "tsc -b packages/{babel-jest,babel-plugin-jest-hoist,diff-sequences,expect}/src/__tests__",
116+
"typecheck:tests": "tsc -b packages/{babel-jest,babel-plugin-jest-hoist,diff-sequences,expect,expect-utils,jest-circus}/src/__tests__",
117117
"verify-old-ts": "node ./scripts/verifyOldTs.mjs",
118118
"verify-pnp": "node ./scripts/verifyPnP.mjs",
119119
"watch": "yarn build:js && node ./scripts/watch.mjs",

packages/expect-utils/src/__tests__/isError.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {isError} from '../utils';
1616
// Copied from https://github.com/graingert/angular.js/blob/a43574052e9775cbc1d7dd8a086752c979b0f020/test/AngularSpec.js#L1883
1717
describe('isError', () => {
1818
function testErrorFromDifferentContext(
19-
createError: (win: Window) => Error | null,
19+
createError: (win: Window | typeof globalThis) => Error | null,
2020
) {
2121
const iframe = document.createElement('iframe');
2222
document.body.appendChild(iframe);
@@ -46,16 +46,19 @@ describe('isError', () => {
4646
});
4747

4848
it('should detect errors from another context', () => {
49-
testErrorFromDifferentContext(win => new win.Error());
49+
testErrorFromDifferentContext(
50+
win => new (win as typeof globalThis).Error(),
51+
);
5052
});
5153

5254
it('should detect DOMException errors from another context', () => {
5355
testErrorFromDifferentContext(win => {
5456
try {
5557
win.document.querySelectorAll('');
56-
} catch (e: any) {
57-
return e;
58+
} catch (e) {
59+
return e as Error;
5860
}
61+
5962
return null;
6063
});
6164
});

packages/jest-circus/src/__mocks__/testEventHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import {Circus} from '@jest/types';
8+
import type {Circus} from '@jest/types';
99

1010
const testEventHandler: Circus.EventHandler = (event, state) => {
1111
switch (event.name) {
@@ -59,4 +59,5 @@ const testEventHandler: Circus.EventHandler = (event, state) => {
5959
console.log(`unhandledErrors: ${String(state.unhandledErrors.length)}`);
6060
}
6161
};
62+
6263
export default testEventHandler;

packages/jest-circus/src/__tests__/circusItFailingTestError.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
import type {Global} from '@jest/types';
99

10+
// Aliases of `it` and `test` to avoid collision with global testing APIs.
1011
let circusIt: Global.It;
1112
let circusTest: Global.It;
1213

1314
const aliasCircusIt = () => {
14-
const {it, test} = require('../');
15+
const {it, test} = require('../') as typeof import('../');
1516
circusIt = it;
1617
circusTest = test;
1718
};

packages/jest-circus/src/__tests__/circusItTestError.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77

88
import type {Global} from '@jest/types';
99

10+
// Aliases of `it` and `test` to avoid collision with global testing APIs.
1011
let circusIt: Global.It;
1112
let circusTest: Global.It;
1213

13-
// using jest-jasmine2's 'it' to test jest-circus's 'it'. Had to differentiate
14-
// the two with this alias.
15-
1614
const aliasCircusIt = () => {
17-
const {it, test} = require('../');
15+
const {it, test} = require('../') as typeof import('../');
1816
circusIt = it;
1917
circusTest = test;
2018
};

packages/jest-circus/src/__tests__/circusItTodoTestError.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77

88
import type {Global} from '@jest/types';
99

10+
// Alias of `it` to avoid collision with global testing APIs.
1011
let circusIt: Global.It;
1112

12-
// using jest-jasmine2's 'it' to test jest-circus's 'it'. Had to differentiate
13-
// the two with this alias.
14-
1513
const aliasCircusIt = () => {
16-
const {it} = require('../');
14+
const {it} = require('../') as typeof import('../');
1715
circusIt = it;
1816
};
1917

packages/jest-circus/src/__tests__/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"compilerOptions": {
44
"rootDir": "../"
55
},
6-
"include": ["../**/*"]
6+
"include": ["../**/*"],
7+
"references": [{"path": "../../"}]
78
}

0 commit comments

Comments
 (0)