Open
Description
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 on isActive
and isExactActive
slot props.
Currently the RouterLinkStub
component doesn't work with the slot api.
Steps to reproduce
components/ToTest.vue
<template>
<ul>
<router-link v-slot="{ href, navigate, isActive }" :to="{ name: 'index' }" custom>
<li :class="{ 'class-logic-to-test': isActive && foo }">
<a :href="href" @click="navigate">Some link</a>
</li>
</router-link>
</ul>
</template>
<script>
export default {
name: 'ToTest',
props: {
foo: {
type: Boolean,
default: true
}
}
}
</script>
tests/ToTest.spec.js
import { mount, RouterLinkStub } from '@vue/test-utils'
import ToTest from '@/components/ToTest.vue'
describe('ToTest', () => {
test('is a Vue instance', () => {
const wrapper = mount(ToTest, {
propsData: {
foo: true
},
stubs: {
RouterLink: RouterLinkStub
}
})
expect(wrapper.html()).toContain('class-logic-to-test')
})
})
Expected behaviour
The RouterLinkStub component should render the content of the slot. Wich is with the exemple:
<li class="class-logic-to-test">
<a href="index">Some Link</a>
</li>
Actual behaviour
The component renders:
<a custom=""></a>
Possible Solution
Rewrite the RouterLinkStub component to support the custom
props and the slot
api