Skip to content

Commit

Permalink
chore: add typechecks for tests of expect-utils and jest-circus (j…
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas committed Oct 6, 2022
1 parent a905b13 commit e23c5c7
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"test": "yarn lint && yarn jest",
"typecheck": "yarn typecheck:examples && yarn typecheck:tests",
"typecheck:examples": "tsc -p examples/angular --noEmit && tsc -p examples/expect-extend --noEmit && tsc -p examples/typescript --noEmit",
"typecheck:tests": "tsc -b packages/{babel-jest,babel-plugin-jest-hoist,diff-sequences,expect}/src/__tests__",
"typecheck:tests": "tsc -b packages/{babel-jest,babel-plugin-jest-hoist,diff-sequences,expect,expect-utils,jest-circus}/src/__tests__",
"verify-old-ts": "node ./scripts/verifyOldTs.mjs",
"verify-pnp": "node ./scripts/verifyPnP.mjs",
"watch": "yarn build:js && node ./scripts/watch.mjs",
Expand Down
11 changes: 7 additions & 4 deletions packages/expect-utils/src/__tests__/isError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {isError} from '../utils';
// Copied from https://github.com/graingert/angular.js/blob/a43574052e9775cbc1d7dd8a086752c979b0f020/test/AngularSpec.js#L1883
describe('isError', () => {
function testErrorFromDifferentContext(
createError: (win: Window) => Error | null,
createError: (win: Window | typeof globalThis) => Error | null,
) {
const iframe = document.createElement('iframe');
document.body.appendChild(iframe);
Expand Down Expand Up @@ -46,16 +46,19 @@ describe('isError', () => {
});

it('should detect errors from another context', () => {
testErrorFromDifferentContext(win => new win.Error());
testErrorFromDifferentContext(
win => new (win as typeof globalThis).Error(),
);
});

it('should detect DOMException errors from another context', () => {
testErrorFromDifferentContext(win => {
try {
win.document.querySelectorAll('');
} catch (e: any) {
return e;
} catch (e) {
return e as Error;
}

return null;
});
});
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-circus/src/__mocks__/testEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {Circus} from '@jest/types';
import type {Circus} from '@jest/types';

const testEventHandler: Circus.EventHandler = (event, state) => {
switch (event.name) {
Expand Down Expand Up @@ -59,4 +59,5 @@ const testEventHandler: Circus.EventHandler = (event, state) => {
console.log(`unhandledErrors: ${String(state.unhandledErrors.length)}`);
}
};

export default testEventHandler;
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

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

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

const aliasCircusIt = () => {
const {it, test} = require('../');
const {it, test} = require('../') as typeof import('../');
circusIt = it;
circusTest = test;
};
Expand Down
6 changes: 2 additions & 4 deletions packages/jest-circus/src/__tests__/circusItTestError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@

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

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

// using jest-jasmine2's 'it' to test jest-circus's 'it'. Had to differentiate
// the two with this alias.

const aliasCircusIt = () => {
const {it, test} = require('../');
const {it, test} = require('../') as typeof import('../');
circusIt = it;
circusTest = test;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@

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

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

// using jest-jasmine2's 'it' to test jest-circus's 'it'. Had to differentiate
// the two with this alias.

const aliasCircusIt = () => {
const {it} = require('../');
const {it} = require('../') as typeof import('../');
circusIt = it;
};

Expand Down
3 changes: 2 additions & 1 deletion packages/jest-circus/src/__tests__/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"compilerOptions": {
"rootDir": "../"
},
"include": ["../**/*"]
"include": ["../**/*"],
"references": [{"path": "../../"}]
}

0 comments on commit e23c5c7

Please sign in to comment.