Vue Cli 4.0.5 Mocha:无法运行测试

时间:2019-11-02 21:32:58

标签: vuejs2 mocha vue-cli-3

对于某些人来说,这很容易解决。

在Windows 10上安装了这样的vue应用:

vue create hello-world

我选择了Mocha作为测试系统,其中存在“ tests” 目录,并带有一个名为 example.spec.js

的示例单元测试。

然后

cd hello-world

然后

npm run test

这是错误:

> hello-world@0.1.0 test C:\UwAmp\www\hello-world
> echo 'Error: no test specified'

'Error: no test specified'

这是我的vue-cli版本:

vue --version
@vue/cli 4.0.5

这是我的package.json文件,未修改:

{
  "name": "hello-world",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "test:unit": "vue-cli-service test:unit",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "core-js": "^3.3.2",
    "vue": "^2.6.10",
    "vue-router": "^3.1.3"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^4.0.0",
    "@vue/cli-plugin-eslint": "^4.0.0",
    "@vue/cli-plugin-router": "^4.0.0",
    "@vue/cli-plugin-unit-mocha": "^4.0.0",
    "@vue/cli-service": "^4.0.0",
    "@vue/test-utils": "1.0.0-beta.29",
    "babel-eslint": "^10.0.3",
    "chai": "^4.1.2",
    "eslint": "^5.16.0",
    "eslint-plugin-vue": "^5.0.0",
    "vue-template-compiler": "^2.6.10"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "rules": {},
    "parserOptions": {
      "parser": "babel-eslint"
    },
    "overrides": [
      {
        "files": [
          "**/__tests__/*.{j,t}s?(x)"
        ],
        "env": {
          "mocha": true
        }
      }
    ]
  },
  "postcss": {
    "plugins": {
      "autoprefixer": {}
    }
  },
  "browserslist": [
    "> 1%",
    "last 2 versions"
  ]
}

也尝试此命令:     vue-cli-service测试:单位

'vue-cli-service' is not recognized

编辑:已解决

我在win 10 64上使用过此命令,现在它可以正常工作:

npx vue-cli-service test:unit

0 个答案:

没有答案