如何使用 Jest 和 vue-cli 更新快照
How to update snapshot with Jest and vue-cli
我应该可以在 运行 我的测试中添加 -u
参数,但我不知道为什么它不起作用:
npm run test ComponentName.spec.js -u
npm run test ComponentName.spec.js --updateSnapshot
但它不起作用。我的 package.json:
"scripts": {
"test": "vue-cli-service test:unit",
我知道我可以只删除快照文件,但我想弄清楚为什么该命令不起作用。
基于the docs:
npm run test -- -u
我验证了这个有效。
在 vue-cli 3 中,您常用的 npm 命令调用 vue-cli-service 而不是开玩笑了。 Vue-cli-service会为你叫笑话
你可以 运行 :
npm run test:unit -- -u
--
必须将下一个参数传递给子命令。
或
npx vue-cli-service test:unit -u
这将 运行 测试和升级快照。
yarn test -u
对我有用。我们使用纱线。
npm 运行 测试 -- -u [file_path]
//对于特定的文件(thumps up to echo's answer)
如果您运行正在使用 Lerna monorepo 进行项目,
您可能想要将新脚本添加到包的 package.json
文件中:
{
// ...
"scripts": {
// ...
"test:update:snapshot": "jest --updateSnapshot"
// ...
}
// ...
}
所以你可以运行
npx lerna run test:update:snapshot
或者您可以只输入包裹然后运行
npm run test -- -u
基本上 --
告诉你的命令参数 -u
是它的子命令。
我应该可以在 运行 我的测试中添加 -u
参数,但我不知道为什么它不起作用:
npm run test ComponentName.spec.js -u
npm run test ComponentName.spec.js --updateSnapshot
但它不起作用。我的 package.json:
"scripts": {
"test": "vue-cli-service test:unit",
我知道我可以只删除快照文件,但我想弄清楚为什么该命令不起作用。
基于the docs:
npm run test -- -u
我验证了这个有效。
在 vue-cli 3 中,您常用的 npm 命令调用 vue-cli-service 而不是开玩笑了。 Vue-cli-service会为你叫笑话
你可以 运行 :
npm run test:unit -- -u
--
必须将下一个参数传递给子命令。
或
npx vue-cli-service test:unit -u
这将 运行 测试和升级快照。
yarn test -u
对我有用。我们使用纱线。
npm 运行 测试 -- -u [file_path] //对于特定的文件(thumps up to echo's answer)
如果您运行正在使用 Lerna monorepo 进行项目,
您可能想要将新脚本添加到包的 package.json
文件中:
{
// ...
"scripts": {
// ...
"test:update:snapshot": "jest --updateSnapshot"
// ...
}
// ...
}
所以你可以运行
npx lerna run test:update:snapshot
或者您可以只输入包裹然后运行
npm run test -- -u
基本上 --
告诉你的命令参数 -u
是它的子命令。