-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
useRoute is undefined when following vue-test-utils guide to test with Composition API #1466
Comments
I thought #1465 would fix this but it doesn't seem to affect it. It's as if vite or vitest was requiring a different vue-router module in @patak-dev do you have any idea what might be happening here? |
Is this related to vitest-dev/vitest#1484 or vitejs/vite#8659? |
Yes, it seems related. We have this issue with version 4.1+ of vue-router. Using the latest version, the following mocks make the tests fail
When changing the mocks like this, the tests will succeed again.
So, the workaround is to mock the .mjs version until vitejs/vite#8659 has been fixed |
I've been searching for this issue and workaround for the past few hours! |
@rros been looking for this for hours, thanks!! If you have a minute could you please explain why this works? |
I am experiencing the same problem, but not with mocked router. I experience it with real router. When i follow these instructions: for me
both always are undefined. i am trying to fix this the whole day. Without success. Now i found this ticket here, but it is related to mocked router, how a solution for real router could look like? Any idea? Cause i am quite desperate on this since hours. |
Well i adpated your approach and adjusted my imports from Then it is also working for the "real router" approach. |
This solution actually doesn't work for me. |
This workaround works if you are using certain versions of vitest. For example, in the "reproduction link" the version ^0.18 of vitest is used. The example works, with the workaround described, until version ^0.23 of vitest. Since version 0.24 of vitest, the workaround doesn't work anymore and the result of |
Will the vue version downgrade to 3.3.4 can use the specific source code what wrong do not know |
This seems to be now resolved with the latest versions of vitest, vite, and test-utils |
Version
Reproduction link
github.com
Steps to reproduce
What is expected?
useRoute should be mocked and return the mocked value
What is actually happening?
useRoute is undefined
When following the guide on vue-test-utils how to test vue-router with Composition API (see https://test-utils.vuejs.org/guide/advanced/vue-router.html#using-a-mocked-router-with-composition-api), the test fails.
The reason for that is that useRoute is undefined. The last version where it's working like described is 4.0.16.
The text was updated successfully, but these errors were encountered: