Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass refs to functional component stubs #1293

Merged
merged 1 commit into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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