-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Add type tests for all expect
matchers
#11949
Conversation
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. |
@@ -431,7 +431,7 @@ const expectExport = expect as Expect; | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
|
@@ -182,7 +170,7 @@ export interface Matchers<R> { | |||
* Ensure that an object is an instance of a class. | |||
* This matcher uses `instanceof` underneath. | |||
*/ | |||
toBeInstanceOf(expected: Function): R; | |||
toBeInstanceOf(expected: unknown): R; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow unknown
here feels like better idea, or?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is ...expected: [unknown, ...Array<unknown>]
better than ...expected: unknown[]
? isn't it the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
expect
matchers.Of course, I was looking through the code while working with typings.
Found one issue with the typings of
<...>CalledWith
matchers. Previous typings allowed to use the matchers without any arguments. I improved these, but strangelymlh-tsd
is 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.