Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install @testing-library/vue by default instead of @vue/test-utils #6228

Open
Robin-Hoodie opened this issue Jan 20, 2021 · 5 comments
Open
Labels
intend to implement The team has the intention to implement this feature at some point. Contribution is also welcome. scope: unit-jest scope: unit-mocha

Comments

@Robin-Hoodie
Copy link
Contributor

What problem does this feature solve?

In the official documentation on testing, the following is mentioned when suggesting the 2 libraries that can be used for testing:

Vue Test Utils is the official low-level component testing library that was written to provide users access to Vue specific APIs. If you are new to testing Vue applications, we would recommend using Vue Testing Library, which is an abstraction over Vue Test Utils.

The recommendation for new users is to use @testing-library/vue.
However, @vue/cli-plugin-unit-jest doesn't actually install @testing-library/vue, but @vue/test-utils

I find it to be unintuitive that despite the recommendation, the more low-level (and "harder to use") alternative is installed by default.

It's probably not a good idea to install both by default, but if we have to pick one, @testing-library/vue seems like the obvious choice to me.

The users who would be more likely to go with @vue/test-utils instead, are more likely to be more experienced, and will have a better understanding of the alternatives.

What does the proposed API look like?

Change

'@vue/test-utils': isVue3 ? '^2.0.0-0' : '^1.0.3'
to add @testing-library/vue instead

Happy to open a PR on this myself

@haoqunjiang haoqunjiang added intend to implement The team has the intention to implement this feature at some point. Contribution is also welcome. scope: unit-jest scope: unit-mocha labels Jan 21, 2021
@haoqunjiang
Copy link
Member

Yeah, it would be great to use an easier-to-use testing library by default. But I have zero experience with it. So any PR is very welcome!

@Robin-Hoodie
Copy link
Contributor Author

I just noticed that @testing-library/vue doesn't have support for Vue 3 yet

It's probably best to keep the current behaviour then until that is supported

@afontcu
Copy link
Member

afontcu commented Feb 7, 2021

Hi! Vue Testing Library maintainer here. 👋

We're still ironing out our integration with Vue 3, but we're almost there. I'll keep an eye on this issue and ping you back when VTL for Vue 3 is marked as stable.

It's probably not a good idea to install both by default

Actually Vue Testing Library relies on Vue Test Utils, so you might end up with both libraries installed under the hood (even though you might only want to use VTL 😄)

Thanks!

@rfgonzalezweb
Copy link

What do you guys recommends for testing for now?

I'm using Laravel + Inertia + Vue 3 and I can't make testing with Jest to work.

I keep getting errors that leads to version issues like:

SyntaxError: Cannot use import statement outside a module

@curtisblackwell
Copy link

@rfgonzalezweb This may be too late, but if you create a babel.config.js, that'll likely solve that problem for you.

module.exports = {
    presets: [["@babel/preset-env", { targets: { node: "current" } }]],
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
intend to implement The team has the intention to implement this feature at some point. Contribution is also welcome. scope: unit-jest scope: unit-mocha
Projects
None yet
Development

No branches or pull requests

5 participants