58

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.

reymon359
  • 1,240
  • 2
  • 11
  • 34
Nikolay Dyankov
  • 6,491
  • 11
  • 58
  • 79

5 Answers5

142

Based on the docs:

npm run test -- -u

I verified this works.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
echo
  • 2,666
  • 1
  • 25
  • 17
15

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.

Samuel-Zacharie Faure
  • 1,047
  • 11
  • 26
10

yarn test -u worked for me. We use yarn.

B. Bulpett
  • 814
  • 12
  • 27
4

npm run test -- -u [file_path] //for particular file (thumps up to echo's answer)

3

If you are running a project with Lerna monorepo,

You probably want to add a new script to your package's package.json file:

{
// ...
"scripts": {
  // ...
  "test:update:snapshot": "jest --updateSnapshot"
  // ...
}
// ...
}

So you can run

npx lerna run test:update:snapshot

Or you can just enter the package and run

npm run test -- -u

Basically -- tells your command the argument -u is for its child command.

ofundefined
  • 2,692
  • 2
  • 18
  • 35