Skip to content

Commit

Permalink
Merge pull request #1293 from xanf/fix-refs-on-functional-with-shallow
Browse files Browse the repository at this point in the history
fix: pass refs to functional component stubs
  • Loading branch information
lmiller1990 authored Jan 3, 2020
2 parents 7b7263f + 6f5a592 commit d291171
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/create-instance/create-component-stubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ function getCoreProperties(componentOptions: Component): Object {
props: componentOptions.props,
on: componentOptions.on,
key: componentOptions.key,
ref: componentOptions.ref,
domProps: componentOptions.domProps,
class: componentOptions.class,
staticClass: componentOptions.staticClass,
Expand Down Expand Up @@ -96,6 +95,7 @@ export function createStubFromComponent(
return h(
tagName,
{
ref: componentOptions.functional ? context.data.ref : undefined,
attrs: componentOptions.functional
? {
...context.props,
Expand Down
24 changes: 24 additions & 0 deletions test/specs/mounting-options/stubs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,30 @@ describeWithShallowAndMount('options.stub', mountingMethod => {
expect(wrapper.html()).to.contain('h1')
})

it('maintains refs to components', () => {
const FunctionalComponentPassingRef = {
functional: true,
render: (h, context) => h('div', context.data)
}

const TestComponent = {
template: `
<div>
<test-component ref="normalChild" />
<test-functional-component ref="functionalChild" />
</div>
`,
components: {
testComponent: Component,
testFunctionalComponent: FunctionalComponentPassingRef
}
}

const wrapper = mountingMethod(TestComponent)
expect(wrapper.vm.$refs.normalChild).to.exist
expect(wrapper.vm.$refs.functionalChild).to.exist
})

it('uses original component stub', () => {
const Stub = {
template: '<div />'
Expand Down

0 comments on commit d291171

Please sign in to comment.