-
-
Notifications
You must be signed in to change notification settings - Fork 361
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
How to use this with unit tests? #41
Comments
@antfu seems like quite a few people stumbling with this. Is there a solution for using this plugin with unit testing? |
I would suggest to use cypress, which will just work. |
Yes, but they are different things. I use cypress and that works fine. But what about testing components in isolation i.e. unit tests? |
@husayt Cypress has a component testing solution for Vue now that's built on top of Vue Test Utils + Vite - it came out in the last couple of major Cypress versions. This might be what @antfu is referring to. I haven't tested it with this package but I've been using it where I would have used jest component tests in the past: https://www.cypress.io/blog/2021/04/06/getting-start-with-cypress-component-testing-vue-2-3/ |
I have high hopes for vite-jest, if/when that's stable it should solve this problem. I'm running in to the same issue with Another option is to write a standalone Jest transformer, maybe some of the internal plugin logic here can be reused. |
Bumping this up - was really excited to make use of it, now that I migrated to Vite... but with 500+ unit tests, this needs to be fixed first 😬 |
So the simple answer to this seems to be now: Use vitest for testing! |
|
^ Exactly. Vitest seems interesting, but it's not battle-tested like Jest is, so it's still be best to wait for vite-jest to ship |
@eratio08 how do you solve this with vitest? do you have any examples? |
@TetianaPozniakovaClone I did not try to use this plugin yet but using vite + vitest should allow to at least make the code injection/generation that is done by this plugin work that would not work with jest before. |
@eratio08 yes, components stubs. And somehow items-list is only stubbed when I explicitly add: P.S. I think I should create a new thread for this :) |
Mh I never had a use case for stub components to I cant comment on that. I would just use |
This doesn't work with with stubs: example: import { describe, it, expect } from 'vitest';
import { render } from '@testing-library/vue';
import SomeComponent from './SomeComponent.vue';
describe('SomeComponent', () => {
it('renders correct template styles', async () => {
const { html } = render(SomeComponent, {
stubs: [
'SomeComponentHeader',
],
});
expect(html()).toMatchSnapshot();
});
}); If I import Use case: For now i'm resorting to simply have the imports in file. but would be nice to figure out why this doesn't work with vitest + Vue Test Utils out of the box? Shallow mount solves this a bit but you get this snapshot, with // Vitest Snapshot v1
exports[`SomeComponent > renders correct template styles 1`] = `
<div class="p-4 rounded-md">
<anonymous-stub some-prop="Some prop"></anonymous-stub>
</div>
`; as opossed to // Vitest Snapshot v1
exports[`SomeComponent > renders correct template styles 1`] = `
<div class="p-4 rounded-md">
<some-component-header-stub some-prop="Some prop"></some-component-header-stub>
</div>
`; |
There is no workaround for this yet? 😭 |
@Neophen that's because |
This fix should allow stubbing autoimported components vuejs/vue-test-utils#2017 |
I am glad at least some migration tooling like this lib exists but what kind of suggestion is that to "just use cypress"? I have around 1500 unit tests. There is no way I am rewriting them in Cypress. I appreciate this lib as a temporary solution (too bad tooling like this does not come from the official Vue team), but if I had to use it permanently, I would rather rewrite the frontend in Angular or React than keep using Vue. @Djaler I am on 1.3.6 and it still does not work |
As this is a vite plugin it won't be utilized when running unit test and all components won't be transformed.
Is there any trick to get this working with the
vue-test-utils
/jest
?The text was updated successfully, but these errors were encountered: