fix(jest-snapshot): fix typings of snapshot matchers#13240
fix(jest-snapshot): fix typings of snapshot matchers#13240SimenB merged 5 commits intojestjs:mainfrom mrazauskas:fix-jest.Mock-usage
Conversation
| - `[expect]` Expose `ExpectationResult` type ([#13240])(https://github.com/facebook/jest/pull/13240)) | ||
| - `[jest-snapshot]` Expose `Context` type ([#13240])(https://github.com/facebook/jest/pull/13240)) |
There was a problem hiding this comment.
I used those in type tests, but in a way they can be useful to defined matcher functions (ExpectationResult) or to implement snapshot matchers (Context).
| beforeEach(() => { | ||
| throwMatcher = toThrowErrorMatchingSnapshot.bind({ | ||
| snapshotState: {match: matchFn}, | ||
| }); | ||
| }); |
There was a problem hiding this comment.
.bind was reworked into .call, which proofed to be friendlier with types. Also mocks are cleared in afterEach calling jest.clearAllMocks().
|
|
||
| expect(matchFn).toHaveBeenCalledWith( | ||
| expect.objectContaining({received: 'coconut', testName: ''}), | ||
| expect(mockedMatch).toBeCalledTimes(1); |
There was a problem hiding this comment.
Just to be sure that mock was cleared.
| export const toMatchSnapshot: MatcherFunctionWithContext< | ||
| Context, | ||
| [propertiesOrHint?: object | string, hint?: string] | ||
| > = function (received, propertiesOrHint, hint) { |
There was a problem hiding this comment.
Here and bellow – types in function signature is the only change. The rest is white space / formatting.
|
Actually this particular bug could be caught by typechecking the test files. I will try to set this up. |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Split from #13238
Summary
While reworking
jest.Mockusage in tests ofjest-snapshotpackage, I noticed that types of matchers are incorrect. To be preciseMatcherFunctionWithContextwas not used correctly and because of that matchers imported into tests had wrong types. Ups.. I introduced this some time ago.Fixed everything and added type tests to prevent regression in the future.
Also cleaned up
jest.Mockusage.Test plan
Green CI.