【问题标题】:vuejs unit testing, default installation says no test specifiedvuejs单元测试,默认安装说没有指定测试
【发布时间】:2019-07-01 13:18:25
【问题描述】:

在 Windows 7 上。使用 VueJS UI 实用程序安装了一个新的 vue 项目。设置单元测试/启用开玩笑。添加了通天塔。

在命令行运行“npm test”会返回'Error: no test specified'

我在 package.json 文件中设置了典型的 "scripts": { "vue-cli-service test:unit" }

jest.config.js 具有预期的匹配模式:

{  testMatch: [
    '**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)'
  ] }

因此,它甚至找不到位于 tests/unit/example.spec.js 中的示例文件。

奇怪的是,我可以让它找到我直接从 node_modules 目录运行的测试,使用vue-cli-service

node_modules\.bin\vue-cli-service test:unit

从那里我得到了一个 babel transpile 问题(它无法识别 example.spec.js 文件中的 ES6 import 命令).. 这是另一个噩梦,也许不适合这篇文章。

尝试更新 npm(使用 6.9.2)。 Vue cli 版本是3.8.2。尝试删除 node_modules 目录。 非常感谢任何帮助。

运行npm test后,错误如下:

> testing_research@0.1.0 test C:\Users\allan.luchenitser\sandbox\testing_research
> echo 'Error: no test specified'

'Error: no test specified'

再次感谢,

【问题讨论】:

    标签: javascript node.js unit-testing vue.js babeljs


    【解决方案1】:

    您的package.json"scripts" 应该包含一个命名脚本。示例:

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

    此外,您必须配置jest 以解析您项目中的任何.js.ts 测试文件,将此配置添加到您的package.json

    "jest": {
      "moduleFileExtensions": [
        "js",
        "ts",
        "json",
        "vue"
      ],
      "transform": {
        ".*\\.(vue)$": "vue-jest"
      }
    }
    

    现在运行 npm run test:unit 应该会找到并运行您项目中的所有测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-13
      • 2017-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-07
      相关资源
      最近更新 更多