Skip to content

Commit 2d6b497

Browse files
authoredJul 4, 2020
fix: allow using findComponent on a functional component (#1593)
1 parent 5eb9ab1 commit 2d6b497

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed
 

‎packages/test-utils/src/wrapper.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ export default class Wrapper implements BaseWrapper {
237237
*/
238238
findComponent(rawSelector: Selector): Wrapper | ErrorWrapper {
239239
const selector = getSelector(rawSelector, 'findComponent')
240-
if (!this.vm) {
240+
if (!this.vm && !this.isFunctionalComponent) {
241241
throwError(
242242
'You cannot chain findComponent off a DOM element. It can only be used on Vue Components.'
243243
)

‎test/specs/wrapper/find.spec.js

+12
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ describeWithShallowAndMount('find', mountingMethod => {
162162
.with.property('message', message)
163163
})
164164

165+
it('allows using findComponent on functional component', () => {
166+
const FuncComponentWithChildren = {
167+
functional: true,
168+
components: {
169+
ChildComponent: Component
170+
},
171+
render: h => h('div', {}, [h(Component)])
172+
}
173+
const wrapper = mountingMethod(FuncComponentWithChildren)
174+
expect(wrapper.findComponent(Component).exists()).to.be.true
175+
})
176+
165177
itSkipIf(isRunningPhantomJS, 'returns Wrapper of class component', () => {
166178
const TestComponent = {
167179
template: `

0 commit comments

Comments
 (0)
Please sign in to comment.