testing-library/vue-testing-library

Installing on Nuxt / Vue2 project following the docs fails due to wrong test-utils version

lbsn opened this issue · 4 comments

lbsn commented

Describe the bug

I'm using vue-testing-library with Nuxt and Vue2. Based on the docs installation should be done using the command:

npm install --save-dev @testing-library/vue

That will install the latest version of @testing-library/vue (currently 6.5.1) which under the hood is using version 2.0.0-rc.18 of @vue/test-utils. This version of test-utils is not compatible with Vue2 (v1 should be used instead) and results in error when running the test suite:

Cannot find module '@vue/compiler-dom' from 'node_modules/@testing-library/vue/node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js'

Apparently the latest version of @testing-library/vue compatible with Nuxt / Vue2 is 5.8.2 and that should probably be clarified in the docs.

To Reproduce

  • Create a new Nuxt project with Jest as test runner (npx create-nuxt-app foo-project)
  • Install @testing-library/vue with npm install --save-dev @testing-library/vue
  • Write a test using @testing-library/vue
  • Run npm run test

Related information:

  • @testing-library/vue version: 6.5.1
  • Vue version: 2.6.14
  • Nuxt version: 2.15.8
rordi commented

I just run into the same problem, but you can install from the v5 version, i.e. "@testing-library/vue": "^5.8.0".

As per the release tags in this repo it seems the latest v6 track is for Vue 3 while the v5 track is for Vue 2.

lbsn commented

I just run into the same problem, but you can install from the v5 version, i.e. "@testing-library/vue": "^5.8.0".

As per the release tags in this repo it seems the latest v6 track is for Vue 3 while the v5 track is for Vue 2.

Sure, I was rather pointing out that the docs are inaccurate on this point. And it seems to me that the information is nowhere to find, one has to look at the package.json in order to know that v5 is for Vue 2.

I was having the same problem here. Thank you for clarifying. v5.8.2 worked for me.

Docs updated. thanks everyone.