Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add typecheck for expect tests #13383

Merged
merged 11 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}/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
Original file line number Diff line number Diff line change
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 & {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case typings have to be added like this. TypeScript is not happy about merging declaration of AsymmetricMatchers interface – it goes looking for expect object in ../index.ts, does not find properties from the declaration and complains.

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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import fc from 'fast-check';
import expect from '..';
import expect from '../';
import {
anythingSettings,
assertSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import fc from 'fast-check';
import expect from '..';
import expect from '../';
import {
anythingSettings,
assertSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import fc from 'fast-check';
import expect from '..';
import expect from '../';
import {
anythingSettings,
assertSettings,
Expand Down
Original file line number Diff line number Diff line change
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
Loading