Skip to content

Commit

Permalink
fix: Pass props to functional component (#1513)
Browse files Browse the repository at this point in the history
* chore: Add regression tests for #1490

* fix: Pass props to functional component
  • Loading branch information
freakzlike committed May 20, 2022
1 parent bb1a378 commit 8bb8a93
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/mount.ts
Expand Up @@ -295,9 +295,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')
})
})

0 comments on commit 8bb8a93

Please sign in to comment.