testing-library / vue-testing-library

🦎 Simple and complete Vue.js testing utilities that encourage good testing practices.
http://testing-library.com/vue
MIT License
1.07k stars 111 forks source link

`render` requires projects to add `vuex` as a dependency #259

Closed adam-gipril closed 7 months ago

adam-gipril commented 2 years ago

Description

This project lists vuex as a dev dependency, but then the implementation of render requires vuex. As a result, consuming projects that may not use vuex in their project code need to add it as a dev dependency to use render in the test environment.

Steps to reproduce

Expected behavior

I'd expect vuex to be a dependency and not a dev dependency of this project as one of its key exports requires vuex.

Related information

afontcu commented 2 years ago

Hi! Just gave it a go locally, and Vuex isn't required (and thus nothing fails) unless a store option is passed, as expected. The minute I add a store: {} option, then I get the error "Cannot find module 'vuex' from 'render.js'". Is it possible that your tests are setting a store?

adam-gipril commented 2 years ago

@afontcu I don't believe any of our tests are setting a store. For additional context, the test suites with which I'm working are for a component library. All our current tests are using @vue/test-utils directly, and I'm not seeing any of those using a store option either.

The only suite that uses the testing library in our project is the following very simple one below. We're currently using Mocha, and plan to swap over to Jest soon.

import { render } from '@testing-library/vue';
import { PCard } from '@/components/PCard';

describe('PCard', () => {
  it('renders slotted-in content', () => {
    render(PCard, { slots: { default: 'Hello world' } }).getByText('Hello world');
  });
});

My error output when running that test is as follows:

 ERROR  Failed to compile with 1 error

This dependency was not found:

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

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

 WEBPACK  Failed to compile with 1 error(s)

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

  Module not found: 'vuex' in '/<my-project-directory>/node_modules/@testing-library/vue/dist'

 ERROR  mochapack exited with code 1.
npm ERR! Test failed.  See above for more details.
afontcu commented 2 years ago

Hi @adam-gipril! Thanks for the update. I'll take a look soon and ping you back

afontcu commented 2 years ago

@adam-gipril could you provide a small reproduction link – with your mocha setup? I can't find a way to reproduce it in several codebases, and now I'm starting to think it has to do with the test runner somehow

adam-gipril commented 2 years ago

@afontcu I'll get you something and ping again. Might not be today — the repo in question is private, and I'll see if I can create a similar testing setup in a small public repo.

afontcu commented 2 years ago

Hi @adam-gipril – and happy new year! Could you check if this had something to do with the test runner?