-
Notifications
You must be signed in to change notification settings - Fork 156
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
ReferenceError: Vue is not defined while using shallowMount #479
Comments
Same here 😞 FAIL __test__/component.spec.js
● Test suite failed to run
ReferenceError: Vue is not defined
> 1 | import {mount} from '@vue/test-utils';
| ^
2 | import Component from '../src/js/Component';
3 |
4 | describe('Loading component', () => {
at Object.<anonymous> (node_modules/.pnpm/@vue+test-utils@2.0.0_vue@3.2.37/node_modules/@vue/test-utils/dist/vue-test-utils.browser.js:8318:8)
at Object.<anonymous> (__test__/component.spec.js:1:1) Everything seems to be latest "@vue/compiler-sfc": "^3.2.37",
"@vue/test-utils": "^2.0.0",
"@vue/vue3-jest": "^28.0.0",
"jest": "^28.1.1",
"jest-environment-jsdom": "^28.1.1",
"vue": "^3.2.37",
"vue-loader": "^17.0.0", It was working fine with jest v27.x P.S. |
thank you @ankurk91 .. let me try downgrading on the versions and see how it goes. also thank you for the explanation |
This answer fixed the problem for me:
don't know why unfortunately, but works fine now. relevant deps below - we use both testing-library and vue/test-utils
|
Thank you @scottnath .. let me try doing the same |
Thanks, your solution worked |
The solution worked for me too. Thank you @scottnath . Closing this thread as solution provided above is working |
This is great to have working. Should there be an explanation of why a random setting is necessary (which wasn't in vue-test-utils v1) somewhere in the docs perhaps? This solution is ... not obvious. (is it bc my environment is set to 'jsdom'? 🤔 ) |
@thedamon pretty easy to find the explanation, it's into Jest official docs: https://jestjs.io/docs/configuration#testenvironmentoptions-object When Another way to solve this is to add an entry into |
Hey I got this same error in when working with karma. can you help me with that ? |
I think it's only "easy to find" the explanation if you already know the reason and therefore which option to look up in the API docs |
@scottnath cool !it solved my problem, thanks a lot |
I am working on vue project and while doing unit testing using jest, I am getting following error for shallowMount:
Following is my unit test code:
Following is my Component code:
Just wonder if I am doing something wrong with unit test or the component code or does the jest and other supporting libraries require version upgrade/downgrade?
The text was updated successfully, but these errors were encountered: