Open rudolfbyker opened 1 year ago
This may be more of a Vuetify issue, since Vuetify uses useLink and the errors are thrown from Vuetify components.
In any case, I'm also having this issue. Its frustrating because you can't stub RouterLink anywhere because it breaks tests.
This may be more of a Vuetify issue
It seems like RouterLinkStub
is breaking the API contract, not Vuetify. But I might be mistaken.
I had the same issue, and manage to make it work by extending the stub and mocking useLink
.
But I had to move the new stub to config.global.mocks
, probably because of the new mocked function? Or not? 🤔😅
// Import vue test utils functions and stubs
import { RouterLinkStub, config } from '@vue/test-utils'
// Global stubs
const RouterLinkStb = { ...RouterLinkStub, useLink: vi.fn() }
// Define plugins, mocks, stubs...
config.global.stubs = {
// Stub is not working here, still the same issue "RouterLink.useLink is not a function"
// RouterLink: RouterLinkStb,
}
config.global.mocks = {
// No more errors here, and tests are OK
RouterLink: RouterLinkStb
}
Subject of the issue
RouterLink.useLink
is missing when usingRouterLinkStub
.Steps to reproduce
VBtn
with theto
prop somewhere, e.g.MyComponent.vue
:Use
RouterLinkStub
in a test:Expected behaviour
MyComponent
is mounted in the test, andVBtn
works.Actual behaviour
Possible Solution
Include the
RouterLink.useLink
function in the stub, since it seems to be part of the API.