From 92d8eb8a7aba239c1fda799cc4506613cddfece1 Mon Sep 17 00:00:00 2001 From: freakzlike Date: Thu, 19 May 2022 20:52:43 +0200 Subject: [PATCH 1/2] chore: Add regression tests for #1490 --- tests/mountingOptions/props.spec.ts | 10 ++++++++++ tests/setProps.spec.ts | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/tests/mountingOptions/props.spec.ts b/tests/mountingOptions/props.spec.ts index adb1f4c8a..86f44f6bf 100644 --- a/tests/mountingOptions/props.spec.ts +++ b/tests/mountingOptions/props.spec.ts @@ -1,5 +1,6 @@ import { defineComponent, h } from 'vue' import { mount } from '../../src' +import Title from '../components/FunctionComponent' describe('mountingOptions.props', () => { const Component = defineComponent({ @@ -85,4 +86,13 @@ describe('mountingOptions.props', () => { expect(onCustomEvent).toHaveBeenCalledTimes(3) }) + + test('props with functional component', async () => { + const wrapper = mount(Title, { + props: { + title: 'Hello' + } + }) + expect(wrapper.text()).toBe('Hello') + }) }) diff --git a/tests/setProps.spec.ts b/tests/setProps.spec.ts index b5b3bcfbc..1107945ab 100644 --- a/tests/setProps.spec.ts +++ b/tests/setProps.spec.ts @@ -1,6 +1,7 @@ import { defineComponent, h, computed } from 'vue' import { mount } from '../src' +import Title from './components/FunctionComponent' describe('setProps', () => { it('updates a primitive prop', async () => { @@ -143,4 +144,14 @@ describe('setProps', () => { 'You can only use setProps on your mounted component' ) }) + + it('sets props for functional component', async () => { + const wrapper = mount(Title) + + await wrapper.setProps({ + title: 'Hello' + }) + + expect(wrapper.text()).toBe('Hello') + }) }) From f3cbd2ada5ac47f054ec64cff27ba5c4f43980ee Mon Sep 17 00:00:00 2001 From: freakzlike Date: Thu, 19 May 2022 20:57:58 +0200 Subject: [PATCH 2/2] fix: Pass props to functional component --- src/mount.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mount.ts b/src/mount.ts index 483c8b2c7..33de2b5e7 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -293,9 +293,9 @@ export function mount( }, props: originalComponent.props || {}, setup: - (_, { attrs, slots }) => + (props, { attrs, slots }) => () => - h(originalComponent, attrs, slots), + h(originalComponent, { ...props, ...attrs }, slots), ...instanceOptions }) addToDoNotStubComponents(originalComponent)