Skip to content

Commit

Permalink
chore: clean up typechecks of expect test files (jestjs#13393)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas committed Oct 6, 2022
1 parent e23c5c7 commit dfda079
Show file tree
Hide file tree
Showing 4 changed files with 419 additions and 430 deletions.
20 changes: 7 additions & 13 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 importedExpect from '../';
import jestExpect from '../';

expect.addSnapshotSerializer(alignedAnsiStyleSerializer);

importedExpect.extend({
jestExpect.extend({
toBeDivisibleBy(actual: number, expected: number) {
const pass = actual % expected === 0;
const message: () => string = pass
Expand Down Expand Up @@ -52,6 +52,11 @@ importedExpect.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 @@ -64,17 +69,6 @@ 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
12 changes: 7 additions & 5 deletions packages/expect/src/__tests__/spyMatchers.test.ts
Expand Up @@ -7,20 +7,22 @@

import * as Immutable from 'immutable';
import {alignedAnsiStyleSerializer} from '@jest/test-utils';
import importedExpect from '../';
import jestExpect from '../';

expect.addSnapshotSerializer(alignedAnsiStyleSerializer);

importedExpect.extend({
jestExpect.extend({
optionalFn(fn?: unknown) {
const pass = fn === undefined || typeof fn === 'function';
return {message: () => 'expect either a function or undefined', pass};
},
});

const jestExpect = importedExpect as typeof importedExpect & {
optionalFn(fn?: unknown): void;
};
declare module '../types' {
interface AsymmetricMatchers {
optionalFn(fn?: unknown): void;
}
}

// Given a Jest mock function, return a minimal mock of a spy.
const createSpy = (fn: jest.Mock) => {
Expand Down

0 comments on commit dfda079

Please sign in to comment.