diff --git a/packages/create-instance/create-component-stubs.js b/packages/create-instance/create-component-stubs.js index 5b6660761..fc65a775e 100644 --- a/packages/create-instance/create-component-stubs.js +++ b/packages/create-instance/create-component-stubs.js @@ -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, @@ -96,6 +95,7 @@ export function createStubFromComponent( return h( tagName, { + ref: componentOptions.functional ? context.data.ref : undefined, attrs: componentOptions.functional ? { ...context.props, diff --git a/test/specs/mounting-options/stubs.spec.js b/test/specs/mounting-options/stubs.spec.js index 7f398f2db..bfe694712 100644 --- a/test/specs/mounting-options/stubs.spec.js +++ b/test/specs/mounting-options/stubs.spec.js @@ -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: ` +
+ + +
+ `, + 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: '
'