Skip to content

Commit

Permalink
fix: handle extended components in find
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh committed Dec 22, 2017
1 parent 359c805 commit 07ec920
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/lib/find-vue-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function vmCtorMatchesName (vm: Component, name: string): boolean {
export default function findVueComponents (root: Component, componentName: string): Array<Component> {
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)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 17 additions & 1 deletion test/unit/specs/mount/Wrapper/find.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<div><a-component /></div>',
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)
})
Expand Down

0 comments on commit 07ec920

Please sign in to comment.