diff --git a/src/mount.ts b/src/mount.ts index 7183a8021..d32f1b020 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -47,6 +47,8 @@ interface MountingOptions { ? Partial : never props?: Props + /** @deprecated */ + propsData?: Props attrs?: Record slots?: SlotDictionary & { default?: Slot @@ -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 }) diff --git a/test-dts/mount.d-test.ts b/test-dts/mount.d-test.ts index 4f86d147c..2b49d054c 100644 --- a/test-dts/mount.d-test.ts +++ b/test-dts/mount.d-test.ts @@ -20,6 +20,13 @@ expectType( }).vm.a ) +// accept propsData - vm is properly typed +expectType( + mount(AppWithDefine, { + propsData: { a: 'Hello', b: 2 } + }).vm.a +) + // no data provided expectError( mount(AppWithDefine, { diff --git a/tests/mountingOptions/props.spec.ts b/tests/mountingOptions/props.spec.ts index b693ce3af..868628f64 100644 --- a/tests/mountingOptions/props.spec.ts +++ b/tests/mountingOptions/props.spec.ts @@ -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: {