From 965483bf5c1525ca6cc83fbdb8a13790a47df5c9 Mon Sep 17 00:00:00 2001 From: dobromir-hristov Date: Wed, 24 Jun 2020 08:55:39 +0300 Subject: [PATCH] fix: allow using findComponent on a functional component --- packages/test-utils/src/wrapper.js | 2 +- test/specs/wrapper/find.spec.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/test-utils/src/wrapper.js b/packages/test-utils/src/wrapper.js index d98b348c9..6ea73b2cf 100644 --- a/packages/test-utils/src/wrapper.js +++ b/packages/test-utils/src/wrapper.js @@ -237,7 +237,7 @@ export default class Wrapper implements BaseWrapper { */ findComponent(rawSelector: Selector): Wrapper | ErrorWrapper { const selector = getSelector(rawSelector, 'findComponent') - if (!this.vm) { + if (!this.vm && !this.isFunctionalComponent) { throwError( 'You cannot chain findComponent off a DOM element. It can only be used on Vue Components.' ) diff --git a/test/specs/wrapper/find.spec.js b/test/specs/wrapper/find.spec.js index ed3a306f4..ef4d2c4b7 100644 --- a/test/specs/wrapper/find.spec.js +++ b/test/specs/wrapper/find.spec.js @@ -162,6 +162,18 @@ describeWithShallowAndMount('find', mountingMethod => { .with.property('message', message) }) + it('allows using findComponent on functional component', () => { + const FuncComponentWithChildren = { + functional: true, + components: { + ChildComponent: Component + }, + render: h => h('div', {}, [h(Component)]) + } + const wrapper = mountingMethod(FuncComponentWithChildren) + expect(wrapper.findComponent(Component).exists()).to.be.true + }) + itSkipIf(isRunningPhantomJS, 'returns Wrapper of class component', () => { const TestComponent = { template: `