Skip to content

Commit 71a2ac4

Browse files
authored
fix: handle unnamed parent and child components (#768)
1 parent 24ab4c5 commit 71a2ac4

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

packages/test-utils/src/find-vue-components.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,13 @@ function findAllFunctionalComponentsFromVnode (
4747

4848
export function vmCtorMatchesName (vm: Component, name: string): boolean {
4949
return !!(
50-
(vm.$vnode &&
51-
vm.$vnode.componentOptions &&
52-
vm.$vnode.componentOptions.Ctor.options.name === name) ||
53-
(vm._vnode &&
50+
name && (
51+
(vm._vnode &&
5452
vm._vnode.functionalOptions &&
5553
vm._vnode.functionalOptions.name === name) ||
5654
(vm.$options && vm.$options.name === name) ||
5755
(vm.options && vm.options.name === name)
58-
)
56+
))
5957
}
6058

6159
export function vmCtorMatchesSelector (component: Component, selector: Object) {

test/specs/wrapper/find.spec.js

+20
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,26 @@ describeWithShallowAndMount('find', mountingMethod => {
412412
})
413413
})
414414

415+
it('handles unnamed components', () => {
416+
const ChildComponent = {
417+
template: '<div />'
418+
}
419+
const TestComponent = {
420+
template: '<child-component v-if="renderChild" />',
421+
components: { ChildComponent },
422+
data: function () {
423+
return {
424+
renderChild: false
425+
}
426+
}
427+
}
428+
const wrapper = mountingMethod(TestComponent)
429+
430+
expect(wrapper.find(ChildComponent).vnode).to.be.undefined
431+
wrapper.vm.renderChild = true
432+
expect(wrapper.find(ChildComponent).vnode).to.be.an('object')
433+
})
434+
415435
itDoNotRunIf(
416436
mountingMethod.name === 'shallowMount',
417437
'returns a VueWrapper instance by CSS selector if the element binds a Vue instance', () => {

0 commit comments

Comments
 (0)