Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: handle unnamed parent and child components #768

Merged
merged 1 commit into from
Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -398,6 +398,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