Skip to content

Commit 1f39d7c

Browse files
author
WebDevEtc
committed
feat(mount): add (deprecated) support for propsData
- Adds support for mounting with `propsData` option, for backwards compatibility. - propsData is marked as deprecated. See #204
1 parent 1aed7a9 commit 1f39d7c

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/mount.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ interface MountingOptions<Props, Data = {}> {
4747
? Partial<Data>
4848
: never
4949
props?: Props
50+
/** @deprecated */
51+
propsData?: Props
5052
attrs?: Record<string, unknown>
5153
slots?: SlotDictionary & {
5254
default?: Slot
@@ -258,6 +260,7 @@ export function mount(
258260
// Vue's reactivity system will cause a rerender.
259261
const props = reactive({
260262
...options?.attrs,
263+
...options?.propsData,
261264
...options?.props,
262265
ref: MOUNT_COMPONENT_REF
263266
})

test-dts/mount.d-test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ expectType<string>(
2020
}).vm.a
2121
)
2222

23+
// accept propsData - vm is properly typed
24+
expectType<string>(
25+
mount(AppWithDefine, {
26+
propsData: { a: 'Hello', b: 2 }
27+
}).vm.a
28+
)
29+
2330
// no data provided
2431
expectError(
2532
mount(AppWithDefine, {

tests/mountingOptions/props.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ describe('mountingOptions.props', () => {
2626
expect(wrapper.text()).toBe('Message is Hello')
2727
})
2828

29+
test("passes props with 'propsData'", () => {
30+
const wrapper = mount(Component, {
31+
propsData: {
32+
message: 'Hello'
33+
}
34+
})
35+
expect(wrapper.text()).toBe('Message is Hello')
36+
})
37+
38+
test("uses props from 'props' attribute, when 'propsData' also contains same attribute keys", () => {
39+
const wrapper = mount(Component, {
40+
propsData: {
41+
message: 'Hello from propsData'
42+
},
43+
props: {
44+
message: 'Hello from props'
45+
}
46+
})
47+
expect(wrapper.text()).toBe('Message is Hello from props')
48+
})
49+
2950
test('assigns extra properties as attributes on components', () => {
3051
const wrapper = mount(Component, {
3152
props: {

0 commit comments

Comments
 (0)