-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Print jest mock fuctions as MockFunction in jest-snapshot
#4836
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
Conversation
| const indentationNext = indentation + config.indent; | ||
|
|
||
| return printer(mockObject, config, indentation, depth, refs); | ||
| return ( |
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 feels really convoluted to do it this way. @pedrottimark is this necessary to just change the header of the object?
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.
FYI, a solution for a built-in plugin is to call printObjectProperties for example:
But AsymmetricMatcher will soon change not to do that for the reason that I missed when I first read #4835 (comment)
which will make impossible to accidentally match with an object.
Our currently proposed serialization matches instance constructed from ordinary class:
class MockFunction {
constructor(calls = [], name = 'jest.fn()') {
this.calls = calls;
this.name = name;
}
}When I read Mock Functions page to borrow an example for alternative, a question hit me:
Should the serialization also include instances property?
http://facebook.github.io/jest/docs/en/mock-function-api.html#mockfnmockinstances
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 originally had instances as well, but it didn't really provide anything of value.
Codecov Report
@@ Coverage Diff @@
## master #4836 +/- ##
==========================================
- Coverage 59.24% 59.17% -0.08%
==========================================
Files 200 200
Lines 6633 6670 +37
Branches 4 3 -1
==========================================
+ Hits 3930 3947 +17
- Misses 2703 2723 +20
Continue to review full report at Codecov.
|
|
To continue thought from inline comment with a question for me to learn: are there any situations when the expected result for assertion about mock function has both |
|
You mean, because invoking mock function with My mental slow cooker is working on a format which only displays neither, either, or both properties which are non-empty arrays. A format without But I need to sketch what some realistic diffs would look like when snapshot fails. |
|
Nice! |
|
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
Fixes #4835. /cc @mjesun
Test plan
Changed snapshots