Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#61717 chore: replace jest's MatcherUtils a…
Browse files Browse the repository at this point in the history
…nd MatcherState with upstream types from expect by @SimenB

* chore: replace jest's MatcherUtils and MatcherState with upstream types from expect

* update dependency
  • Loading branch information
SimenB authored and shlyren committed Aug 17, 2022
1 parent f8dfbee commit 2fafdeb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 39 deletions.
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

0 comments on commit 2fafdeb

Please sign in to comment.