Skip to content

Commit

Permalink
fix: handle unnamed parent and child components (#768)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh authored Jun 27, 2018
1 parent 24ab4c5 commit 71a2ac4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
8 changes: 3 additions & 5 deletions packages/test-utils/src/find-vue-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 20 additions & 0 deletions test/specs/wrapper/find.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,26 @@ describeWithShallowAndMount('find', mountingMethod => {
})
})

it('handles unnamed components', () => {
const ChildComponent = {
template: '<div />'
}
const TestComponent = {
template: '<child-component v-if="renderChild" />',
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', () => {
Expand Down

0 comments on commit 71a2ac4

Please sign in to comment.