Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jest updateSnapshot for specific test file

Tags:

reactjs

jestjs

I'm trying to figure out how o update a single snapshot file. In the docs it says just add the -t and I presume the file name but thats not working for me.

Example, in terminal I use.

jest -u -t test/js/tests/components/myTestApp.test.js

Any ideas why this would not work. I also added it as a string.

like image 990
me-me Avatar asked Feb 01 '18 21:02

me-me


People also ask

How do I run a single test file in Jest?

In order to run a specific test, you'll need to use the jest command. npm test will not work. To access jest directly on the command line, install it via npm i -g jest-cli or yarn global add jest-cli . Then simply run your specific test with jest bar.

Is snapshot testing worth it?

Snapshot tests are useful when you want to make sure your UI does not change unexpectedly. A typical snapshot test case renders a UI component, takes a snapshot, then compares it to a reference snapshot file stored alongside the test.


1 Answers

In order to update particular snapshot, you can pass name as an argument to your script test command.

In package.json

"test": "jest --verbose"

In command line

npm test "<spec name>" -- -u

OR

npm test "<spec name>" -- --updateSnapshot
like image 98
NightFury Avatar answered Oct 04 '22 21:10

NightFury