Skip to content

Commit 8bb8a93

Browse files
authored
fix: Pass props to functional component (#1513)
* chore: Add regression tests for #1490 * fix: Pass props to functional component
1 parent bb1a378 commit 8bb8a93

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/mount.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ export function mount(
295295
},
296296
props: originalComponent.props || {},
297297
setup:
298-
(_, { attrs, slots }) =>
298+
(props, { attrs, slots }) =>
299299
() =>
300-
h(originalComponent, attrs, slots),
300+
h(originalComponent, { ...props, ...attrs }, slots),
301301
...instanceOptions
302302
})
303303
addToDoNotStubComponents(originalComponent)

tests/mountingOptions/props.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { defineComponent, h } from 'vue'
22
import { mount } from '../../src'
3+
import Title from '../components/FunctionComponent'
34

45
describe('mountingOptions.props', () => {
56
const Component = defineComponent({
@@ -85,4 +86,13 @@ describe('mountingOptions.props', () => {
8586

8687
expect(onCustomEvent).toHaveBeenCalledTimes(3)
8788
})
89+
90+
test('props with functional component', async () => {
91+
const wrapper = mount(Title, {
92+
props: {
93+
title: 'Hello'
94+
}
95+
})
96+
expect(wrapper.text()).toBe('Hello')
97+
})
8898
})

tests/setProps.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { defineComponent, h, computed } from 'vue'
22

33
import { mount } from '../src'
4+
import Title from './components/FunctionComponent'
45

56
describe('setProps', () => {
67
it('updates a primitive prop', async () => {
@@ -143,4 +144,14 @@ describe('setProps', () => {
143144
'You can only use setProps on your mounted component'
144145
)
145146
})
147+
148+
it('sets props for functional component', async () => {
149+
const wrapper = mount(Title)
150+
151+
await wrapper.setProps({
152+
title: 'Hello'
153+
})
154+
155+
expect(wrapper.text()).toBe('Hello')
156+
})
146157
})

0 commit comments

Comments
 (0)