Mocking useRouter and useRoute
See original GitHub issuecurrently you can get the router and current route with useRouter
and useRoute
functions and are not accessible with $router
and $route
functions. The docs are therefor outdated with Vue 3 (https://vue-test-utils.vuejs.org/v2/guide/vue-router.html#using-a-mock-router). Is there a way to mock the router?
<script lang="ts">
import { defineComponent, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
export default defineComponent({
setup() {
const router = useRouter();
const route = useRoute();
},
});
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Mocking useRouter and useRoute · Issue #242 · vuejs/test-utils
currently you can get the router and current route with useRouter and useRoute functions and are not accessible with $router and $route ...
Read more >Mocking vue-router's useRoute() in Jest tests in Vue 3
The computed property is using useRoute() , and it is used in the template. When I make a Jest test on this component,...
Read more >Testing Vue Router
Instead of using a real Vue Router instance, we can create a mock version which ... import { useRouter, useRoute } from 'vue-router'...
Read more >mocking useRouter (just basics) with react testing library (4/6)
In this episode , I create the navbar & product component while writing 3 tests and :1. creating advanced nav links ,2. displaying...
Read more >Read more - back - GitHub Pages
The useRouter hook is basically a shortcut for accessing values from the RouterContext . Therefore in order to test a component with useRouter...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the Example!
i am using this for now.
I am also using the mock strategy, either making a simple router myself with jest.fn or
jest.mock('vue-router', .....)
. Here is an example: https://github.com/lmiller1990/vuejs-composition-course/blob/412a46d48bf0624ed523567b05424aa16c48d67e/src/NewPost.spec.ts#L8We are working on a mock router, but it is not ready for usage yet.
Is there any action to be taken for this issue?