You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When snapshot testing, there is a behavioral difference between property matcher objects nested within other objects, and property matcher objects nested within arrays. Property matcher objects nested within arrays seem to be expecting an exact match of the property objects, while property matcher objects nested within other objects expect a "subset" match.
git clone https://github.com/pcorey/snapshot-inconsistencies
cd snapshot-inconsistencies
yarn install
yarn test
Notice that a test fails.
The first test has thingFour set on the object under test and saved in the committed snapshot, but thingFour is missing from the nested property matcher. This test passes. This seems to be the expected behavior for Jest.
The second test has thingFour set on the object under test and saved in the committed snapshot. However, thingFour is not specified in the property matcher object nested within an array. This test fails because Jest seems to be doing an exact match on this property match object, rather than a subset match. My understanding is that in order to be consistent, this test should subset match the nested object, and pass.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
🐛 Bug Report
When snapshot testing, there is a behavioral difference between property matcher objects nested within other objects, and property matcher objects nested within arrays. Property matcher objects nested within arrays seem to be expecting an exact match of the property objects, while property matcher objects nested within other objects expect a "subset" match.
To Reproduce
I've created a reproduction repo to show off what I'm talking about.
To reproduce:
Notice that a test fails.
The first test has
thingFour
set on the object under test and saved in the committed snapshot, butthingFour
is missing from the nested property matcher. This test passes. This seems to be the expected behavior for Jest.The second test has
thingFour
set on the object under test and saved in the committed snapshot. However,thingFour
is not specified in the property matcher object nested within an array. This test fails because Jest seems to be doing an exact match on this property match object, rather than a subset match. My understanding is that in order to be consistent, this test should subset match the nested object, and pass.After doing some debugging, it looks like the underlying jasmine test passes for both tests (
propertyPass
istrue
), but for the second test,snapshotState.match
results in differences in theactual
andexpected
values.Expected behavior
I would expect both tests to pass.
Link to repl or repo (highly encouraged)
https://github.com/pcorey/snapshot-inconsistencies
Issues without a reproduction link are likely to stall.
Run
npx envinfo --preset jest
Paste the results here:
➜ snapshot-inconsistencies git:(master) npx envinfo --preset jest npx: installed 1 in 2.762s System: OS: macOS 10.14 CPU: (4) x64 Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz Binaries: Node: 11.3.0 - /usr/local/bin/node Yarn: 1.12.3 - /usr/local/bin/yarn npm: 6.4.1 - /usr/local/bin/npm
The text was updated successfully, but these errors were encountered: