Skip to content

Commit 07ec920

Browse files
committed
fix: handle extended components in find
1 parent 359c805 commit 07ec920

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/lib/find-vue-components.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function vmCtorMatchesName (vm: Component, name: string): boolean {
3131
export default function findVueComponents (root: Component, componentName: string): Array<Component> {
3232
const components = root._isVue ? findAllVueComponentsFromVm(root) : findAllVueComponentsFromVnode(root)
3333
return components.filter((component) => {
34-
if (!component.$vnode) {
34+
if (!component.$vnode && !component.$options.extends) {
3535
return false
3636
}
3737
return vmCtorMatchesName(component, componentName)

src/lib/validators.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function isVueComponent (component: any): boolean {
3535
return false
3636
}
3737

38-
return typeof component.render === 'function'
38+
return typeof component.render === 'function' || !!component.extends
3939
}
4040

4141
export function isValidSelector (selector: any): boolean {

test/unit/specs/mount/Wrapper/find.spec.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,23 @@ describe('find', () => {
168168
expect(wrapper.find({ ref: 'foo' })).to.be.an('object')
169169
})
170170

171-
it('returns Wrapper of Vue Components matching the ref in options object', () => {
171+
it('returns Wrapper of Vue Component matching the extended component', () => {
172+
const BaseComponent = {
173+
template: '<div><a-component /></div>',
174+
components: {
175+
AComponent: Component
176+
}
177+
}
178+
const TestComponent = {
179+
extends: BaseComponent,
180+
name: 'test-component'
181+
}
182+
const wrapper = mount(TestComponent)
183+
expect(wrapper.find(TestComponent).exists()).to.equal(true)
184+
expect(wrapper.find(TestComponent).isVueComponent).to.equal(true)
185+
})
186+
187+
it('returns Wrapper of Vue Component matching the ref in options object', () => {
172188
const wrapper = mount(ComponentWithChild)
173189
expect(wrapper.find({ ref: 'child' }).isVueComponent).to.equal(true)
174190
})

0 commit comments

Comments
 (0)