Skip to content

docs: update vue-router documentation #1701

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

Merged
merged 1 commit into from
Oct 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions docs/guides/using-with-vue-router.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,20 @@ shallowMount(Component, {
### Installing Vue Router with localVue

```js
import { shallowMount, createLocalVue } from '@vue/test-utils'
import { mount, createLocalVue } from '@vue/test-utils'
import VueRouter from 'vue-router'

const localVue = createLocalVue()
localVue.use(VueRouter)

shallowMount(Component, {
localVue
mount(Component, {
localVue,
router
})
```

The router instance is available to all children components, this is useful for integration level testing.

### Mocking `$route` and `$router`

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.
Expand All @@ -72,6 +75,8 @@ const wrapper = shallowMount(Component, {
wrapper.vm.$route.path // /some/path
```

> **Note:** the mocked `$route` and `$router` values are not available to children components, either stub this components or use the `localVue` method.

### Common gotchas

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