question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vue testing library depends on vuex and vue-router types

See original GitHub issue

Hi there! For my surprise importing the @testing-library/vue module raises a compilation error due to a dependency with vue-router and vuex.

 ERROR  Failed to compile with 2 errors

These dependencies were not found:

* vue-router in ./node_modules/@testing-library/vue/dist/vue-testing-library.js
* vuex in ./node_modules/@testing-library/vue/dist/vue-testing-library.js

To install them, you can run: npm install --save vue-router vuex
  [=========================] 100% (completed)

 WEBPACK  Failed to compile with 2 error(s)

Error in ./node_modules/@testing-library/vue/dist/vue-testing-library.js

  Module not found: 'vue-router' in '/home/sam/sandbox/opencocos/app/node_modules/@testing-library/vue/dist'

Error in ./node_modules/@testing-library/vue/dist/vue-testing-library.js

  Module not found: 'vuex' in '/home/sam/sandbox/opencocos/app/node_modules/@testing-library/vue/dist'

I’ve tried installing both dependencies and test pass, but I believe it shouldn’t be mandatory in order to run tests, right?

Notice: I’m not using Jest. I’m running tests with Mocha.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
afontcucommented, Jul 30, 2021

I’m not sure If all types are needed, we might add a few to stop the error and that’s It.

Wouldn’t that generate several warnings on loose types if we change the complex ones to any, for instance? no-unsafe-assignment or no-unsafe-call being some of them.

as far as I see VTL shouldn’t rely on those types in any way

Would you define store and routes as any (or anything similar) and call it a day?

1reaction
afontcucommented, Jul 15, 2021

Looks like it is due to VTL types making use of TS definitions from both Router and Vuex. Not sure how to fix this one – maybe simply copy&pasting these types from both libraries into VTL, so that the dependency can go?

https://github.com/testing-library/vue-testing-library/blob/master/types/index.d.ts#L3-L6

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mocking Vuex in Vue unit tests - Medium
Vue is a UI library — so naturally, testing Vue components usually involves asserts whether the UI correctly reflects the state of the...
Read more >
API | Testing Library
Vue Testing Library re-exports everything from DOM Testing Library.
Read more >
Chapter 7. Testing Vuex - Testing Vue.js Applications
Vuex (a state-management library for Vue) is essential for large Vue apps. To become a Vue testing master, you should learn how to...
Read more >
Vue.js Testing Made it Easy (with Testing Library) - maxpou.fr
It's not an easy job since Vuex is based on mutations. Without these lines, you may have problems where test #3 depends on...
Read more >
Testing - Vue.js
Each testing type plays a role in your application's testing strategy and ... Vitest is a unit testing framework designed specifically for this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found