Open existe-deja opened 3 years ago
Seems like a bug - probably need to dive into the RouterStub and see what's going on.
Same here. I'm using the new slot api to create custom behaviour.
So in the meanwhile I extended the router-stub for my purposes to something like this. You may need to add custom
-prop and some logic to the slot props if needed.
import { RouterLinkStub } from '@vue/test-utils'
// ...
const stubs = {
RouterLink: {
...RouterLinkStub,
render() {
return this.$scopedSlots.default({
href: this.to,
navigate: jest.fn(),
isActive: false
})
}
}
}
Sorry guys, all my time is spent on VTU v2 and Vue Jest lately.
I wonder if https://github.com/vuejs/vue-test-utils/pull/1877 will fix this?
Did anyone get to look at this? Happy to give some pointers, I'd love to see this fixed but I can't look at it right now.
As of today, in 1.3.4, this is not working.
@BrevAlessio I think that you can't expect it to be fixed in VTU1 ( sadly ). Based on the last comments from @lmiller1990 in https://github.com/vuejs/vue-test-utils/issues/1564#issuecomment-1424857260 .
So Lachlan, Can I mark this PR as wontfix
and close https://github.com/vuejs/vue-test-utils/pull/1877 as it's all related to stubs?
I think this is actually pretty easy to fix, we'd just need to rework https://github.com/vuejs/vue-test-utils/blob/dev/packages/test-utils/src/components/RouterLinkStub.js to do whatever the OP wants - this is kind of different from the others stubs, since we ship a specific implementation, that's apparently out of date.
Ok, then I can have a look once I'm back
Subject of the issue
I'm testing a Tab handler component. It's highly coupled with
router-link
. Since v3.1.0 it's recommended to use the slot api to handle complex templates. I have to test the behavior of my logic wich depends onisActive
andisExactActive
slot props. Currently theRouterLinkStub
component doesn't work with the slot api.Steps to reproduce
components/ToTest.vue
tests/ToTest.spec.js
Expected behaviour
The RouterLinkStub component should render the content of the slot. Wich is with the exemple:
Actual behaviour
The component renders:
Possible Solution
Rewrite the RouterLinkStub component to support the
custom
props and theslot
api