Skip to content

Commit 002eb3e

Browse files
authored
docs: update vue-router documentation (#1701)
Update documentation to explain differences between using `localVue` and `mocks` and provide examples of the use case for each. A common gotcha with integration testing (which don't stub children) is when using the `mocks` approach the router instance is not available on child components.
1 parent a821908 commit 002eb3e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

docs/guides/using-with-vue-router.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,20 @@ shallowMount(Component, {
4141
### Installing Vue Router with localVue
4242

4343
```js
44-
import { shallowMount, createLocalVue } from '@vue/test-utils'
44+
import { mount, createLocalVue } from '@vue/test-utils'
4545
import VueRouter from 'vue-router'
4646

4747
const localVue = createLocalVue()
4848
localVue.use(VueRouter)
4949

50-
shallowMount(Component, {
51-
localVue
50+
mount(Component, {
51+
localVue,
52+
router
5253
})
5354
```
5455

56+
The router instance is available to all children components, this is useful for integration level testing.
57+
5558
### Mocking `$route` and `$router`
5659

5760
Sometimes you want to test that a component does something with parameters from the `$route` and `$router` objects. To do that, you can pass custom mocks to the Vue instance.
@@ -72,6 +75,8 @@ const wrapper = shallowMount(Component, {
7275
wrapper.vm.$route.path // /some/path
7376
```
7477

78+
> **Note:** the mocked `$route` and `$router` values are not available to children components, either stub this components or use the `localVue` method.
79+
7580
### Common gotchas
7681

7782
Installing Vue Router adds `$route` and `$router` as read-only properties on Vue prototype.

0 commit comments

Comments
 (0)