Skip to content

Commit

Permalink
fix: allow using findComponent on a functional component (#1593)
Browse files Browse the repository at this point in the history
  • Loading branch information
dobromir-hristov committed Jul 4, 2020
1 parent 5eb9ab1 commit 2d6b497
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/test-utils/src/wrapper.js
Expand Up @@ -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.'
)
Expand Down
12 changes: 12 additions & 0 deletions test/specs/wrapper/find.spec.js
Expand Up @@ -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: `
Expand Down

0 comments on commit 2d6b497

Please sign in to comment.