Skip to content

Commit 2792235

Browse files
committed
fix: pass refs to functional component stubs
Fixes vuejs#1292
1 parent a9eea7b commit 2792235

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Diff for: packages/create-instance/create-component-stubs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ function getCoreProperties(componentOptions: Component): Object {
4242
props: componentOptions.props,
4343
on: componentOptions.on,
4444
key: componentOptions.key,
45-
ref: componentOptions.ref,
4645
domProps: componentOptions.domProps,
4746
class: componentOptions.class,
4847
staticClass: componentOptions.staticClass,
@@ -96,6 +95,7 @@ export function createStubFromComponent(
9695
return h(
9796
tagName,
9897
{
98+
// ref: componentOptions.functional ? context.data.ref : undefined,
9999
attrs: componentOptions.functional
100100
? {
101101
...context.props,

Diff for: test/specs/mounting-options/stubs.spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,30 @@ describeWithShallowAndMount('options.stub', mountingMethod => {
525525
expect(wrapper.html()).to.contain('h1')
526526
})
527527

528+
it('maintains refs to components', () => {
529+
const FunctionalComponentPassingRef = {
530+
functional: true,
531+
render: (h, context) => h('div', context.data)
532+
}
533+
534+
const TestComponent = {
535+
template: `
536+
<div>
537+
<test-component ref="normalChild" />
538+
<test-functional-component ref="functionalChild" />
539+
</div>
540+
`,
541+
components: {
542+
testComponent: Component,
543+
testFunctionalComponent: FunctionalComponentPassingRef
544+
}
545+
}
546+
547+
const wrapper = mountingMethod(TestComponent)
548+
expect(wrapper.vm.$refs.normalChild).to.exist
549+
expect(wrapper.vm.$refs.functionalChild).to.exist
550+
})
551+
528552
it('uses original component stub', () => {
529553
const Stub = {
530554
template: '<div />'

0 commit comments

Comments
 (0)