Vue test utils 观看测试

Vue test utils watch tests

如何在编写和保存测试时保留 npm run test:unit 命令 运行,我需要 npm run serve 之类的热重载,我试过 npm run test:unit --watch 但它不起作用。

我建议注册一个新的命令脚本来观看测试以直接使用 vue-cli-service--watch 选项:

package.json

{
  "scripts": {
     // ...
    "test:unit:watch": "vue-cli-service test:unit --watch",
  }
}

那么你会运行:

npm run test:unit:watch // or yarn test:unit:watch

// You can even run for specific test as well

npm run test:unit:watch -- yourTest.spec.ts

npm docs状态:

As of npm@2.0.0, you can use custom arguments when executing scripts. The special option -- is used by getopt to delimit the end of the options. npm will pass all the arguments after the -- directly to your script:

npm run test -- --grep="pattern"

所以在命令行上使用这个:

                  
npm run test:unit -- --watch

或者,您可以使用 yarn,它不需要 run 命令或分隔符 --:

yarn test:unit --watch