react jest confirming snapshot change
Asked Answered
G

2

5

I am newbie at React and I can not find a solution for a simple problem. I am using create-react-app and I succeed to operate jest snapshot test. Then, for trying I changed render() function's inside. Now jest said me × has a valid snapshot (5ms) (I know it is normal.) and it says me:

1 snapshot test failed in 1 test suite. Inspect your code changes or press u to update them.

I don't know how can I update it. I tried to pressing u, ctrl + u and other combinations. But nothing changed in there. I know it is silly question but How can I update them?

Gradual answered 25/7, 2018 at 20:42 Comment(1)
How do you run the test?Neologism
Q
12

you can update the snapshots in two ways:

  1. run npm test and then in the interactive shell press u

  2. run npm test -u, the -u flag tells jest to update snapshots.

You could change npm by yarn if you are using yarn

Quirita answered 25/7, 2018 at 20:49 Comment(1)
In my case I had to run npm test -- -u for the snapshots to update. Probably something that eventually was changed / updated by jestZaria
S
0

In my case, I got this same error because I had components that were using dynamic IDs, UUID, so even after updating the snapshots, every time I would run the test again, the IDs would be new so they would never match, hence test would fail.

I had to rewrite my test to fix this, using Property Matchers from Jest.

Hope this help anyone who encounter this issue and can't find out why is happening.

Stun answered 24/7 at 23:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.