-
-
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
feat(expect, @jest/expect): infer type of *ReturnedWith
matchers argument
#13278
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1b0121b
feat: typed `*ReturnedWith` argument
mrazauskas 00315ce
use `unknown`
mrazauskas 0272238
add changelog entry
mrazauskas 96ab005
simplify
mrazauskas 9db869c
back to `any`s
mrazauskas a3ccd47
Merge branch 'main' into feat-typed-ReturnedWith
mrazauskas 9c166b5
fix order
mrazauskas 539f974
Merge branch 'main' into feat-typed-ReturnedWith
SimenB 90aa595
changelog
SimenB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,21 +247,44 @@ expectError(expect(jest.fn()).toHaveReturnedTimes(true)); | |
expectError(expect(jest.fn()).toHaveReturnedTimes()); | ||
|
||
expectType<void>(expect(jest.fn()).toReturnWith('value')); | ||
expectType<void>(expect(jest.fn<() => string>()).toReturnWith('value')); | ||
expectError(expect(jest.fn<() => number>()).toReturnWith('value')); | ||
expectError(expect(123).toReturnWith('value')); | ||
expectError(expect(jest.fn()).toReturnWith()); | ||
|
||
expectType<void>(expect(jest.fn()).toHaveReturnedWith(123)); | ||
expectType<void>(expect(jest.fn<() => number>()).toHaveReturnedWith(123)); | ||
expectError(expect(jest.fn<() => string>()).toHaveReturnedWith(123)); | ||
expectError(expect(123).toHaveReturnedWith(123)); | ||
expectError(expect(jest.fn()).toHaveReturnedWith()); | ||
|
||
expectType<void>(expect(jest.fn()).lastReturnedWith('value')); | ||
expectType<void>(expect(jest.fn<() => string>()).lastReturnedWith('value')); | ||
expectError(expect(jest.fn<() => number>()).lastReturnedWith('value')); | ||
expectError(expect(123).lastReturnedWith('value')); | ||
expectError(expect(jest.fn()).lastReturnedWith()); | ||
|
||
expectType<void>(expect(jest.fn()).toHaveLastReturnedWith(123)); | ||
expectType<void>(expect(jest.fn<() => number>()).toHaveLastReturnedWith(123)); | ||
expectError(expect(jest.fn<() => string>()).toHaveLastReturnedWith(123)); | ||
expectError(expect(123).toHaveLastReturnedWith(123)); | ||
expectError(expect(jest.fn()).toHaveLastReturnedWith()); | ||
|
||
expectType<void>(expect(jest.fn()).nthReturnedWith(1, 'value')); | ||
expectType<void>(expect(jest.fn<() => string>()).nthReturnedWith(2, 'value')); | ||
expectError(expect(jest.fn<() => number>()).nthReturnedWith(3, 'value')); | ||
expectError(expect(123).nthReturnedWith(4, 'value')); | ||
expectError(expect(123).nthReturnedWith(5)); | ||
expectError(expect(jest.fn()).nthReturnedWith()); | ||
expectError(expect(jest.fn()).nthReturnedWith(2)); | ||
|
||
expectType<void>(expect(jest.fn()).toHaveNthReturnedWith(1, 'value')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works with |
||
expectType<void>( | ||
expect(jest.fn<() => string>()).toHaveNthReturnedWith(2, 'value'), | ||
); | ||
expectError(expect(jest.fn<() => number>()).toHaveNthReturnedWith(3, 'value')); | ||
expectError(expect(123).toHaveNthReturnedWith(4, 'value')); | ||
expectError(expect(123).toHaveNthReturnedWith(5)); | ||
expectError(expect(jest.fn()).toHaveNthReturnedWith()); | ||
expectError(expect(jest.fn()).toHaveNthReturnedWith(2)); | ||
|
||
// snapshot matchers | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
what is this
N
for? 🤔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.
Just three test – takes two type args, but allows passing juts one and (below) errors if type args are missing.
Some time ago I added second arg without default. That was a breaking change and a user raised an issue. This test was added back in these days, but became unnecessary then
@jest/expect
package was introduced. Now it is needed again.One day this will be wrapped with nice
test("required type arguments", () => { /...
. Good enough for now (;