Skip to content
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

docs: add RouterLinkStub to api docs #1391

Merged
merged 1 commit into from Apr 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/api/index.md
Expand Up @@ -1945,3 +1945,32 @@ test('config.global mocks and stubs', () => {
::: tip
Remember that this behavior is global, not on a mount by mount basis. You might need to enable/disable it before and after each test.
:::

## components

### RouterLinkStub

A component to stub the Vue Router `router-link` component when you don't want to mock or include a full router.

You can use this component to find a `router-link` component in the render tree.

**Usage:**

Set as a stub in the mounting options:
```js
import { mount, RouterLinkStub } from '@vue/test-utils'

const wrapper = mount(Component, {
global: {
stubs: {
RouterLink: RouterLinkStub,
},
},
})

expect(wrapper.findComponent(RouterLinkStub).props().to).toBe('/some/path')
```

**Usage with slot:**

The `RouterLinkStub` component supports slot content and will return very basic values for its slot props. If you need more specific slot prop values for your tests, consider using a [real router](../guide/advanced/vue-router.html#using-a-real-router) so you can use a real `router-link` component. Alternatively, you can define your own `RouterLinkStub` component by copying the implementation from the test-utils package.