-
-
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
Omit empty calls array in plugin for mock functions #4848
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4848 +/- ##
==========================================
+ Coverage 59.19% 59.25% +0.06%
==========================================
Files 200 200
Lines 6641 6646 +5
Branches 3 4 +1
==========================================
+ Hits 3931 3938 +7
+ Misses 2710 2708 -2
Continue to review full report at Codecov.
|
exports[`mock with 1 calls and non-default name via new in object 1`] = ` | ||
Object { | ||
"fn": [MockFunction MyConstructor] | ||
calls: Array [ |
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.
This looks pretty weird
I have trouble understanding the grouping in the line that I commented. Shouldn't the
? |
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 like where this is going! On mobile, so a bit hard to read the snapshot-diffs. First glance looks great, though!
|
||
expect(mockWithName).toMatchSnapshot(); | ||
test('maxDepth option', () => { |
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.
Could you add a mock function with a name to a toMatchSnapshot
assertion? I can see it working in this test, but a separate assertion would be awesome!
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.
See MyConstructor
in mock with 1 calls and non-default name via new in object 1
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.
Yes, I can see it working, but it would be sweet with a test of just the name, no calls or wrapping objects
}); | ||
|
||
test('mock with name', () => { |
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.
This test is what I referred to in my comment
@@ -7,30 +7,122 @@ | |||
*/ | |||
'use strict'; | |||
|
|||
const mock = jest.fn(); | |||
const prettyFormat = require('pretty-format'); |
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.
import
|
||
afterEach(() => mock.mockReset()); | ||
const plugin = require('../mock_serializer'); |
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.
import
@cpojer Yes, your wish is my command: #4848 (comment) |
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
Balance the following constraints /cc @mjesun
Before a mock function has been called, serialize it similar to function, especially when it is property of JavaScript object or React element.
Example adapted from #4829 (comment)
Serialize non-empty array so it is impossible to accidentally match with an object #4835 (comment)
EDIT selected different example which has non-default name from a test case:
This pull request makes incremental improvements to:
MockFunction
in jest-snapshot #4836Test plan
10 tests including 5 snapshots