diff --git a/packages/test-utils/src/find-vue-components.js b/packages/test-utils/src/find-vue-components.js index 54c936d9a..be4351ac5 100644 --- a/packages/test-utils/src/find-vue-components.js +++ b/packages/test-utils/src/find-vue-components.js @@ -47,15 +47,13 @@ function findAllFunctionalComponentsFromVnode ( export function vmCtorMatchesName (vm: Component, name: string): boolean { return !!( - (vm.$vnode && - vm.$vnode.componentOptions && - vm.$vnode.componentOptions.Ctor.options.name === name) || - (vm._vnode && + name && ( + (vm._vnode && vm._vnode.functionalOptions && vm._vnode.functionalOptions.name === name) || (vm.$options && vm.$options.name === name) || (vm.options && vm.options.name === name) - ) + )) } export function vmCtorMatchesSelector (component: Component, selector: Object) { diff --git a/test/specs/wrapper/find.spec.js b/test/specs/wrapper/find.spec.js index ae2fb7e62..de02edb42 100644 --- a/test/specs/wrapper/find.spec.js +++ b/test/specs/wrapper/find.spec.js @@ -398,6 +398,26 @@ describeWithShallowAndMount('find', mountingMethod => { }) }) + it('handles unnamed components', () => { + const ChildComponent = { + template: '
' + } + const TestComponent = { + template: '', + components: { ChildComponent }, + data: function () { + return { + renderChild: false + } + } + } + const wrapper = mountingMethod(TestComponent) + + expect(wrapper.find(ChildComponent).vnode).to.be.undefined + wrapper.vm.renderChild = true + expect(wrapper.find(ChildComponent).vnode).to.be.an('object') + }) + itDoNotRunIf( mountingMethod.name === 'shallowMount', 'returns a VueWrapper instance by CSS selector if the element binds a Vue instance', () => {