Skip to content

Commit 99b4cae

Browse files
author
Lindsay Gaines
authored
docs: add RouterLinkStub to api docs (#1391)
1 parent 2ea2197 commit 99b4cae

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/api/index.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,3 +1945,32 @@ test('config.global mocks and stubs', () => {
19451945
::: tip
19461946
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.
19471947
:::
1948+
1949+
## components
1950+
1951+
### RouterLinkStub
1952+
1953+
A component to stub the Vue Router `router-link` component when you don't want to mock or include a full router.
1954+
1955+
You can use this component to find a `router-link` component in the render tree.
1956+
1957+
**Usage:**
1958+
1959+
Set as a stub in the mounting options:
1960+
```js
1961+
import { mount, RouterLinkStub } from '@vue/test-utils'
1962+
1963+
const wrapper = mount(Component, {
1964+
global: {
1965+
stubs: {
1966+
RouterLink: RouterLinkStub,
1967+
},
1968+
},
1969+
})
1970+
1971+
expect(wrapper.findComponent(RouterLinkStub).props().to).toBe('/some/path')
1972+
```
1973+
1974+
**Usage with slot:**
1975+
1976+
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.

0 commit comments

Comments
 (0)