Skip to content
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
3 changes: 3 additions & 0 deletions src/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ interface MountingOptions<Props, Data = {}> {
? Partial<Data>
: never
props?: Props
/** @deprecated */
propsData?: Props
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, what do you think about marking this as deprecated?

https://devblogs.microsoft.com/typescript/announcing-typescript-4-0-beta/#deprecated-support

attrs?: Record<string, unknown>
slots?: SlotDictionary & {
default?: Slot
Expand Down Expand Up @@ -258,6 +260,7 @@ export function mount(
// Vue's reactivity system will cause a rerender.
const props = reactive({
...options?.attrs,
...options?.propsData,
...options?.props,
ref: MOUNT_COMPONENT_REF
})
Expand Down
7 changes: 7 additions & 0 deletions test-dts/mount.d-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ expectType<string>(
}).vm.a
)

// accept propsData - vm is properly typed
expectType<string>(
mount(AppWithDefine, {
propsData: { a: 'Hello', b: 2 }
}).vm.a
)

// no data provided
expectError(
mount(AppWithDefine, {
Expand Down
21 changes: 21 additions & 0 deletions tests/mountingOptions/props.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ describe('mountingOptions.props', () => {
expect(wrapper.text()).toBe('Message is Hello')
})

test("passes props with 'propsData'", () => {
const wrapper = mount(Component, {
propsData: {
message: 'Hello'
}
})
expect(wrapper.text()).toBe('Message is Hello')
})

test("uses props from 'props' attribute, when 'propsData' also contains same attribute keys", () => {
const wrapper = mount(Component, {
propsData: {
message: 'Hello from propsData'
},
props: {
message: 'Hello from props'
}
})
expect(wrapper.text()).toBe('Message is Hello from props')
})

test('assigns extra properties as attributes on components', () => {
const wrapper = mount(Component, {
props: {
Expand Down