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 mismatch after upgrade to React 16 #1480

Closed
2 of 10 tasks
ndresx opened this issue Jan 14, 2018 · 2 comments
Closed
2 of 10 tasks

Snapshot mismatch after upgrade to React 16 #1480

ndresx opened this issue Jan 14, 2018 · 2 comments

Comments

@ndresx
Copy link
Contributor

ndresx commented Jan 14, 2018

I initially thought that this problem could have something to do with Jest, but according to jestjs/jest#5173 it's more likely that either Enzyme and/or React are the source of it after updating from React 15 to React 16.

Current behavior

To briefly describe what's happening - Jest seems to be generating a snapshot immediately instead of waiting for jest.runTimersToTime to run (I'm not sure if there is actually a correlation between these 2 things or not).

This test snapshot output (https://travis-ci.org/ndresx/react-countdown/builds/320673265#L534) shows that the number changed from 6 to 10 seconds after jest.runTimersToTime(6000); was called, while nothing in the code itself was changed, just an update of the packages happened.

Although the state value assertion passes with the expected value of 6 at this point (the value is directly rendered via render),

expect(wrapper.state().seconds).toBe(6);
expect(wrapper).toMatchSnapshot();

the snapshot seems to be taken before the time gets actually changed and writes 10 instead.
Before the update of React, the tests were passing. If you need more info, please let me know.

Expected behavior

The value in the snapshot should still be 6 => not change.

Your environment

API

  • shallow
  • mount
  • render

Version

library version
Enzyme 3.3.0
React 16.2.0

Adapter

  • enzyme-adapter-react-16
  • enzyme-adapter-react-15
  • enzyme-adapter-react-15.4
  • enzyme-adapter-react-14
  • enzyme-adapter-react-13
  • enzyme-adapter-react-helper
  • others ( )
@ljharb
Copy link
Member

ljharb commented Jan 14, 2018

Try adding a wrapper.update() in there before your assertion?

@ndresx
Copy link
Contributor Author

ndresx commented Jan 15, 2018

Works, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants