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 props to functional component #1513

Merged
merged 2 commits into from May 20, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/mount.ts
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions 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({
Expand Down Expand Up @@ -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')
})
})
11 changes: 11 additions & 0 deletions 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 () => {
Expand Down Expand Up @@ -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')
})
})