【问题标题】:Vue test utils watch testsVue test utils 观看测试
【发布时间】:2021-04-03 12:48:44
【问题描述】:

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

【问题讨论】:

    标签: javascript vue.js jestjs vue-cli vue-test-utils


    【解决方案1】:

    我建议注册一个用于观看测试的新命令脚本,以直接使用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
    

    【讨论】:

      【解决方案2】:

      npm docs 状态:

      npm@2.0.0 开始,您可以在执行脚本时使用自定义参数。 getopt 使用特殊选项-- 来分隔选项的结尾。 npm 会将-- 之后的所有参数直接传递给您的脚本:

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

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

                        ?
      npm run test:unit -- --watch
      

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

      yarn test:unit --watch
      

      【讨论】:

        猜你喜欢
        • 2019-10-24
        • 2019-04-17
        • 2019-07-16
        • 1970-01-01
        • 2021-02-17
        • 1970-01-01
        • 2018-09-28
        • 2019-05-02
        • 2018-11-09
        相关资源
        最近更新 更多