Skip to content

Commit 20c7694

Browse files
committed
tests: add test for getComponent with stub
1 parent 704f018 commit 20c7694

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/components/RouterLinkStub.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ export const RouterLinkStub = defineComponent({
1212
},
1313

1414
render() {
15-
return h('a', undefined, this.$slots.default())
15+
return h('a', undefined, this.$slots?.default?.())
1616
}
1717
})

tests/mountingOptions/stubs.global.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { h, ComponentOptions, defineComponent } from 'vue'
22

3-
import { config, mount } from '../../src'
3+
import { config, mount, RouterLinkStub } from '../../src'
44
import Hello from '../components/Hello.vue'
55
import ComponentWithoutName from '../components/ComponentWithoutName.vue'
66
import ComponentWithSlots from '../components/ComponentWithSlots.vue'
@@ -40,12 +40,13 @@ describe('mounting options: stubs', () => {
4040
// https://github.com/vuejs/vue-test-utils-next/issues/249
4141
it('applies stubs globally', () => {
4242
const Comp = defineComponent({
43-
template: '<div><router-link /><router-view /></div>'
43+
template: '<div><foo /><router-link to="/foo" /><router-view /></div>'
4444
})
4545
const wrapper = mount(Comp, {
4646
global: {
4747
stubs: {
48-
RouterLink: true,
48+
Foo: true,
49+
RouterLink: RouterLinkStub,
4950
RouterView: defineComponent({
5051
render() {
5152
return h('span')
@@ -56,8 +57,9 @@ describe('mounting options: stubs', () => {
5657
})
5758

5859
expect(wrapper.html()).toBe(
59-
'<div><router-link-stub></router-link-stub><span></span></div>'
60+
'<div><foo-stub></foo-stub><a></a><span></span></div>'
6061
)
62+
expect(wrapper.getComponent(RouterLinkStub).vm.to).toBe('/foo')
6163
})
6264

6365
it('stubs a functional component by its variable declaration name', () => {

0 commit comments

Comments
 (0)