Add type tests for all expect matchers#11949
Add type tests for all expect matchers#11949SimenB merged 5 commits intojestjs:mainfrom mrazauskas:fix-expect-add-types-test
expect matchers#11949Conversation
|
While I don't mind the combined PR, we could split out the JSDoc changes into its own PR to reduce the diff here to be focused on the type changes? |
Sure. Also will be easier to work on changes. |
| declare namespace expectExport { | ||
| export type MatcherState = JestMatcherState; | ||
| export interface Matchers<R> extends MatcherInterface<R> {} | ||
| export interface Matchers<R, T> extends MatcherInterface<R, T> {} |
There was a problem hiding this comment.
T is consumed in toMatchSnapshot and toMatchInlineSnapshot. Might be useful somewhere else too.
| propertyMatchers: Partial<T>, | ||
| snapshotName?: string, | ||
| ): R; | ||
| toMatchSnapshot(hint?: string): R; |
There was a problem hiding this comment.
Less specific overloads goes first for better errors.
|
|
||
| expectType<void>(expect(jest.fn()).toBeCalledWith('value')); | ||
| expectType<void>(expect(jest.fn()).toBeCalledWith('value', 123)); | ||
| // expectError(expect(jest.fn()).toBeCalledWith()); |
Codecov Report
@@ Coverage Diff @@
## main #11949 +/- ##
=======================================
Coverage 68.76% 68.76%
=======================================
Files 322 322
Lines 16620 16618 -2
Branches 4795 4794 -1
=======================================
- Hits 11429 11428 -1
+ Misses 5159 5158 -1
Partials 32 32
Continue to review full report at Codecov.
|
| * This matcher uses `instanceof` underneath. | ||
| */ | ||
| toBeInstanceOf(expected: Function): R; | ||
| toBeInstanceOf(expected: unknown): R; |
There was a problem hiding this comment.
Somehow unknown here feels like better idea, or?
There was a problem hiding this comment.
I honestly do not understand why it was Function before
since one can pass anything in it I agree with unknown
| toHaveBeenNthCalledWith(nthCall: number, ...args: Array<unknown>): R; | ||
| toHaveBeenNthCalledWith( | ||
| nth: number, | ||
| ...expected: [unknown, ...Array<unknown>] |
There was a problem hiding this comment.
why is ...expected: [unknown, ...Array<unknown>] better than ...expected: unknown[]? isn't it the same?
There was a problem hiding this comment.
it ensures length of array is >= 1 instead of >= 0
|
Fixed the above mentioned Waiting for tsdjs/tsd#127 |
|
@mrazauskas can we remove (or comment out) the assertions that needs a newer version of |
|
Ergh, CI is happy... Can I land this? 😀 |
expect matchersexpect matchers
|
Looked through. I think it is good to land. Not at computer right now, can’t add change log |
|
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. |

Summary
@SimenB As promised, here is an attempt to add type tests for all
expectmatchers.Of course, I was looking through the code while working with typings.
Found one issue with the typings of
<...>CalledWithmatchers. Previous typings allowed to use the matchers without any arguments. I improved these, but strangelymlh-tsdis refusing to understand the errors (expecting an error, getting that error, "but found none"):Test plan
This PR is mainly adding missing tests. All improvements are covered by tests too.