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 binations. But nothing changed in there. I know it is silly question but How can I update them?
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 binations. But nothing changed in there. I know it is silly question but How can I update them?
Share Improve this question edited Jul 26, 2018 at 2:25 coder 8,71216 gold badges41 silver badges54 bronze badges asked Jul 25, 2018 at 20:42 devneeddevdevneeddev 3035 silver badges11 bronze badges 1- How do you run the test? – Nimeshka Srimal Commented Jul 26, 2018 at 3:01
2 Answers
Reset to default 12you can update the snapshots in two ways:
run
npm test
and then in the interactive shell pressu
run
npm test -u
, the-u
flag tells jest to update snapshots.
You could change npm
by yarn
if you are using yarn
In my case, I got this same error because I had ponents 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.