From 07ec920cf28e25e88fef7f3bbd1c00c37ab46c0d Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Fri, 22 Dec 2017 10:55:15 +0000 Subject: [PATCH] fix: handle extended components in find --- src/lib/find-vue-components.js | 2 +- src/lib/validators.js | 2 +- test/unit/specs/mount/Wrapper/find.spec.js | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/lib/find-vue-components.js b/src/lib/find-vue-components.js index dd74fbc5d..20adaffed 100644 --- a/src/lib/find-vue-components.js +++ b/src/lib/find-vue-components.js @@ -31,7 +31,7 @@ export function vmCtorMatchesName (vm: Component, name: string): boolean { export default function findVueComponents (root: Component, componentName: string): Array { const components = root._isVue ? findAllVueComponentsFromVm(root) : findAllVueComponentsFromVnode(root) return components.filter((component) => { - if (!component.$vnode) { + if (!component.$vnode && !component.$options.extends) { return false } return vmCtorMatchesName(component, componentName) diff --git a/src/lib/validators.js b/src/lib/validators.js index 3677b7a8d..55d0d030b 100644 --- a/src/lib/validators.js +++ b/src/lib/validators.js @@ -35,7 +35,7 @@ export function isVueComponent (component: any): boolean { return false } - return typeof component.render === 'function' + return typeof component.render === 'function' || !!component.extends } export function isValidSelector (selector: any): boolean { diff --git a/test/unit/specs/mount/Wrapper/find.spec.js b/test/unit/specs/mount/Wrapper/find.spec.js index f52476eb6..6cde85f70 100644 --- a/test/unit/specs/mount/Wrapper/find.spec.js +++ b/test/unit/specs/mount/Wrapper/find.spec.js @@ -168,7 +168,23 @@ describe('find', () => { expect(wrapper.find({ ref: 'foo' })).to.be.an('object') }) - it('returns Wrapper of Vue Components matching the ref in options object', () => { + it('returns Wrapper of Vue Component matching the extended component', () => { + const BaseComponent = { + template: '
', + components: { + AComponent: Component + } + } + const TestComponent = { + extends: BaseComponent, + name: 'test-component' + } + const wrapper = mount(TestComponent) + expect(wrapper.find(TestComponent).exists()).to.equal(true) + expect(wrapper.find(TestComponent).isVueComponent).to.equal(true) + }) + + it('returns Wrapper of Vue Component matching the ref in options object', () => { const wrapper = mount(ComponentWithChild) expect(wrapper.find({ ref: 'child' }).isVueComponent).to.equal(true) })