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(jest): add mocked
property
#57775
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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.
since we adding
jest-mock
dependency hereshould we need to import all types/functions exported by
jest-mock
like this. No ?so that it looks consistent :)
or it doesn't matter
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.
For now it doesn't matter as this is a new API whereas the existing types are slightly different from what's provided in
jest-mock
so need to be checked first and that's not as important as typing the new api.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.
won't this break for people who have e.g.
?
(Long term I want
@types/jest
to import all of its things from Jest itself (#44365), but as long as that's not the case, mixing seems less than ideal?)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 you've provided isn't actually valid because
jest.Mock
is actually sort of poorly namedjest.MockedFunction
, where asjest.mocked({})
returnsjest.MockedObject
.However no it won't because the types should all be compatible.
here's some code showcasing this
Regardless of what combination you use (e.g. types from
jest-mocked
+mocked
from thejest
global, everything fromjest-mocked
, everything fromts-jest
, renaming thejest.<type>
to beMockTypes.<type>
, etc) the errors and passes are the same.The first and last
doSomething
method calls have errors because of type issues (which basically boil down to the conditional typing ofmocked
resulting in a more accurate type than what's being used) while the middle two calls don't.That was part of my goal here, as we're already mixing types with
jest-diff
andpretty-format
- but I didn't want to change the existing types in this PR because of the size of that work.However looking at it with fresh eyes, it'll be a better IDE experience anyway to go with #57776 so let's do that.
https://github.com/DefinitelyTyped/DefinitelyTyped/pull/57776/files#r772003152
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.
(the problem with #57776 is it is mixing types too, but it's more subtle because they have slightly different names)