Skip to content

Commit

Permalink
chore: add typecheck for expect tests (#13383)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas committed Oct 4, 2022
1 parent dcd39f0 commit c660c16
Show file tree
Hide file tree
Showing 9 changed files with 503 additions and 238 deletions.
2 changes: 1 addition & 1 deletion package.json
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}/src/__tests__",
"typecheck:tests": "tsc -b packages/{babel-jest,babel-plugin-jest-hoist,diff-sequences,expect}/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
20 changes: 13 additions & 7 deletions packages/expect/src/__tests__/extend.test.ts
Expand Up @@ -9,11 +9,11 @@
import {equals, iterableEquality, subsetEquality} from '@jest/expect-utils';
import {alignedAnsiStyleSerializer} from '@jest/test-utils';
import * as matcherUtils from 'jest-matcher-utils';
import jestExpect from '../';
import importedExpect from '../';

expect.addSnapshotSerializer(alignedAnsiStyleSerializer);

jestExpect.extend({
importedExpect.extend({
toBeDivisibleBy(actual: number, expected: number) {
const pass = actual % expected === 0;
const message: () => string = pass
Expand Down Expand Up @@ -52,11 +52,6 @@ jestExpect.extend({
});

declare module '../types' {
interface AsymmetricMatchers {
toBeDivisibleBy(expected: number): void;
toBeSymbol(expected: symbol): void;
toBeWithinRange(floor: number, ceiling: number): void;
}
interface Matchers<R> {
toBeDivisibleBy(expected: number): R;
toBeSymbol(expected: symbol): R;
Expand All @@ -69,6 +64,17 @@ declare module '../types' {
}
}

const jestExpect = importedExpect as typeof importedExpect & {
not: {
toBeDivisibleBy(expected: number): void;
toBeWithinRange(floor: number, ceiling: number): void;
};

toBeDivisibleBy(expected: number): void;
toBeSymbol(expected: symbol): void;
toBeWithinRange(floor: number, ceiling: number): void;
};

it('is available globally when matcher is unary', () => {
jestExpect(15).toBeDivisibleBy(5);
jestExpect(15).toBeDivisibleBy(3);
Expand Down
Expand Up @@ -7,7 +7,7 @@
*/

import fc from 'fast-check';
import expect from '..';
import expect from '../';
import {
anythingSettings,
assertSettings,
Expand Down
Expand Up @@ -7,7 +7,7 @@
*/

import fc from 'fast-check';
import expect from '..';
import expect from '../';
import {
anythingSettings,
assertSettings,
Expand Down
Expand Up @@ -7,7 +7,7 @@
*/

import fc from 'fast-check';
import expect from '..';
import expect from '../';
import {
anythingSettings,
assertSettings,
Expand Down
Expand Up @@ -8,7 +8,7 @@

import * as assert from 'assert';
import fc from 'fast-check';
import expect from '..';
import expect from '../';
import {
anythingSettings,
assertSettings,
Expand Down

0 comments on commit c660c16

Please sign in to comment.