最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - react jest confirming snapshot change - Stack Overflow

programmeradmin3浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 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

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.

发布评论

评论列表(0)

  1. 暂无评论