Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update snapshot with Jest and vue-cli

I should be able to add -u parameter when running my tests, but I can't figure out why it doesn't work:

npm run test ComponentName.spec.js -u npm run test ComponentName.spec.js --updateSnapshot 

but it doesn't work. My package.json:

"scripts": {     "test": "vue-cli-service test:unit", 

I know I can just delete the snapshot files, but I'd like to figure out why the command doesn't work.

like image 880
Nikolay Dyankov Avatar asked May 03 '19 07:05

Nikolay Dyankov


2 Answers

Based on the docs:

npm run test -- -u 

I verified this works.

like image 156
echo Avatar answered Sep 23 '22 08:09

echo


In vue-cli 3, your usual npm command calls vue-cli-service and not jest anymore. Vue-cli-service will call jest for you.

Either you can run :

npm run test:unit -- -u

the -- is so that the next arguments have to be passed to the subcommand.

Or

npx vue-cli-service test:unit -u

This will run the tests and upgrade the snapshots.

like image 45
Samuel Faure Avatar answered Sep 25 '22 08:09

Samuel Faure