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: replace jest's MatcherUtils and MatcherState with upstream types from expect #61717

Merged
merged 2 commits into from Aug 15, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 25 additions & 30 deletions types/jest/index.d.ts
Expand Up @@ -543,27 +543,21 @@ declare namespace jest {

type EqualityTester = (a: any, b: any) => boolean | undefined;

interface MatcherUtils {
readonly isNot: boolean;
readonly dontThrow: () => void;
readonly promise: string;
readonly assertionCalls: number;
readonly expectedAssertionsNumber: number | null;
readonly isExpectingAssertions: boolean;
readonly suppressedErrors: any[];
readonly expand: boolean;
readonly testPath: string;
readonly currentTestName: string;
utils: typeof import('jest-matcher-utils') & {
iterableEquality: EqualityTester;
subsetEquality: EqualityTester;
};
/**
* This is a deep-equality function that will return true if two objects have the same values (recursively).
*/
equals(a: any, b: any, customTesters?: EqualityTester[], strictCheck?: boolean): boolean;
[other: string]: any;
}
type MatcherUtils = Pick<
import('expect').MatcherState,
| 'isNot'
| 'dontThrow'
| 'promise'
| 'assertionCalls'
| 'expectedAssertionsNumber'
| 'isExpectingAssertions'
| 'suppressedErrors'
| 'expand'
| 'testPath'
| 'currentTestName'
| 'utils'
| 'equals'
> & { [other: string]: any; };

interface ExpectExtendMap {
[key: string]: CustomMatcher;
Expand Down Expand Up @@ -619,15 +613,16 @@ declare namespace jest {
*/
stringContaining(str: string): any;
}
interface MatcherState {
assertionCalls: number;
currentTestName: string;
expand: boolean;
expectedAssertionsNumber: number;
isExpectingAssertions?: boolean | undefined;
suppressedErrors: Error[];
testPath: string;
}
type MatcherState = Pick<
import('expect').MatcherState,
| 'assertionCalls'
| 'currentTestName'
| 'expand'
| 'expectedAssertionsNumber'
| 'isExpectingAssertions'
| 'suppressedErrors'
| 'testPath'
>;
/**
* The `expect` function is used every time you want to test a value.
* You will rarely call `expect` by itself.
Expand Down
16 changes: 8 additions & 8 deletions types/jest/jest-tests.ts
Expand Up @@ -782,15 +782,15 @@ switch (mockResult.type) {
expect.setState(true);
expect.setState({for: 'state'});
const expectState = expect.getState();
// $ExpectType string
// $ExpectType string | undefined
expectState.currentTestName;
// $ExpectType string
// $ExpectType string | undefined
expectState.testPath;
// $ExpectType boolean
// $ExpectType boolean | undefined
expectState.expand;
// $ExpectType number
expectState.assertionCalls;
// $ExpectType number
// $ExpectType number | null | undefined
expectState.expectedAssertionsNumber;
// $ExpectType boolean | undefined
expectState.isExpectingAssertions;
Expand Down Expand Up @@ -910,7 +910,7 @@ expect.extend({
expect.extend({
foo(this: jest.MatcherContext) {
const isNot: boolean = this.isNot;
const expand: boolean = this.expand;
const expand: boolean | undefined = this.expand;

const expectedColor = this.utils.EXPECTED_COLOR('blue');
const receivedColor = this.utils.EXPECTED_COLOR('red');
Expand Down Expand Up @@ -953,10 +953,10 @@ expect.extend({

const equals: boolean = this.equals({}, {});

this.dontThrow();
this.dontThrow!();
this.fromState;
const currentTestName: string = this.currentTestName;
const testPath: string = this.testPath;
const currentTestName: string | undefined = this.currentTestName;
const testPath: string | undefined = this.testPath;

return {
message: () => `Can use ${this.promise} for failure message`,
Expand Down
2 changes: 1 addition & 1 deletion types/jest/package.json
@@ -1,7 +1,7 @@
{
"private": true,
"dependencies": {
"jest-matcher-utils": "^28.0.0",
"expect": "^28.0.0",
"pretty-format": "^28.0.0"
},
"exports": {
Expand Down