From 2d6b49780c7e1d663b877ddf5d6492ed7b510379 Mon Sep 17 00:00:00 2001 From: Dobromir Hristov Date: Sat, 4 Jul 2020 03:27:01 +0300 Subject: [PATCH] fix: allow using findComponent on a functional component (#1593) --- 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: `