1

After installing Vue Testing Library (by doing npm install --save-dev @testing-library/vue) I tried to run the example test by doing:

npm run test:unit

Straight away I'm getting this error:

'vue-cli-service' is not recognized as an internal or external command, operable program or batch file.

Tried npm i to no avail.

Any idea what's going on?

EDIT: jest.config.js

module.exports = {
  preset: '@vue/cli-plugin-unit-jest/presets/no-babel'
}

package.json

{
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "build": "nuxt build",
    "test:unit": "vue-cli-service test:unit",
    "lint": "npm run lint:js",
    "dev": "nuxt",
    "generate": "nuxt generate",
    "lint:js": "eslint --ext \".js,.vue\" --ignore-path .gitignore .",
    "start": "nuxt start"
  },
  "dependencies": {
    "@nuxtjs/axios": "^5.12.5",
    "core-js": "^3.8.3",
    "nuxt": "^2.14.12",
    "nuxt-lazy-load": "^1.2.5",
    "vue-lottie": "^0.2.1",
    "vue-ripple-directive": "^2.0.1"
  },
  "devDependencies": {
    "@nuxtjs/eslint-config": "^5.0.0",
    "@nuxtjs/eslint-module": "^3.0.2",
    "@nuxtjs/router": "^1.5.1",
    "@nuxtjs/style-resources": "^1.0.0",
    "@nuxtjs/svg": "^0.1.12",
    "@nuxtjs/tailwindcss": "^3.4.2",
    "@tailwindcss/postcss7-compat": "^2.0.3",
    "@testing-library/vue": "^5.6.1",
    "autoprefixer": "^9.8.6",
    "babel-eslint": "^10.1.0",
    "eslint": "^7.18.0",
    "eslint-plugin-nuxt": "^2.0.0",
    "eslint-plugin-vue": "^7.5.0",
    "node-sass": "^5.0.0",
    "postcss": "^7.0.35",
    "sass-loader": "^10.1.1",
    "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.0.3"
  }
}
drake035
  • 3,955
  • 41
  • 119
  • 229
  • please give the output of `vue --version` in the command line – Boussadjra Brahim Mar 14 '21 at 17:53
  • OK, I see `@vue/cli 4.5.11` – drake035 Mar 14 '21 at 18:09
  • mmmm, for nuxt it might need some extra config which is not explained in any doc/tutorial – Boussadjra Brahim Mar 14 '21 at 18:25
  • I thought about that, but then it is not my Nuxt app who is affected since I'm running the script independently of the Nuxt app. Also the issue seems rooted to a more basic level. – drake035 Mar 14 '21 at 18:40
  • nuxt projects don't use vue cli (vue-cli-service), I've this project that's configured to use this library https://github.com/Dawntraoz/full-static-nuxt-storyblok – Boussadjra Brahim Mar 14 '21 at 19:49
  • Thanks! I tried to replicate what she did by installing 3 more testing packages she uses, but no luck so far. Getting errors. I created a separate question for it: https://stackoverflow.com/questions/66637556/how-to-use-vue-testing-library-with-nuxt-js – drake035 Mar 15 '21 at 11:58

1 Answers1

0

This is because in your package.json in the scripts section you are running a vue-cli-service command before test:unit

You will need to download and install the vue-cli-service before you can use it: vue-cli-service

Or delete the words 'vue-cli-service' from your test script command if you're not using it.

Sweet Chilly Philly
  • 3,014
  • 2
  • 27
  • 37