Skip to content
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
docs: update vue-router documentation
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.
  • Loading branch information
blake-newman committed Oct 1, 2020
commit f1b6cda63c35cabc3bc7a0f7c099e4961a8d5414
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