Skip to content
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

Snapshot inconsistencies when working with nested property matchers #8151

Closed
pcorey opened this issue Mar 18, 2019 · 4 comments
Closed

Snapshot inconsistencies when working with nested property matchers #8151

pcorey opened this issue Mar 18, 2019 · 4 comments

Comments

@pcorey
Copy link

pcorey commented Mar 18, 2019

🐛 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:

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.

After doing some debugging, it looks like the underlying jasmine test passes for both tests (propertyPass is true), but for the second test, snapshotState.match results in differences in the actual and expected 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
@jeysal
Copy link
Contributor

jeysal commented Mar 19, 2019

Confirmed - I agree this is a bug

@yofriadi
Copy link

I think this is duplicate of #7089

@SimenB
Copy link
Member

SimenB commented Apr 22, 2019

Yes it is, thanks!

@SimenB SimenB closed this as completed Apr 22, 2019
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants