diff --git a/src/mount.ts b/src/mount.ts index d0883b504..4abf1c42e 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -54,9 +54,7 @@ export function mount< ComponentProps, ComponentData & ComponentExposed & Omit> > -> & { - LOOL: Exclude> -} +> // implementation export function mount( diff --git a/src/vueWrapper.ts b/src/vueWrapper.ts index e1d1e774e..0209dbb4d 100644 --- a/src/vueWrapper.ts +++ b/src/vueWrapper.ts @@ -244,7 +244,7 @@ export class VueWrapper< return nextTick() } - setProps(props: T['$props']): Promise { + setProps(props: Partial): Promise { // if this VM's parent is not the root or if setProps does not exist, error out if (this.vm.$parent !== this.rootVM || !this.__setProps) { throw Error('You can only use setProps on your mounted component') diff --git a/test-dts/wrapper.d-test.ts b/test-dts/wrapper.d-test.ts index 811376ab7..1582f3d95 100644 --- a/test-dts/wrapper.d-test.ts +++ b/test-dts/wrapper.d-test.ts @@ -120,25 +120,49 @@ expectType<{ [key: string]: any }>(wrapper.props()) const ComponentWithProps = defineComponent({ props: { foo: String, - bar: Number, - }, + bar: Number + } }) -const propsWrapper = mount(ComponentWithProps); +const propsWrapper = mount(ComponentWithProps) -propsWrapper.setProps({foo: 'abc'}) -propsWrapper.setProps({foo: 'abc', bar: 123}) +propsWrapper.setProps({ foo: 'abc' }) +propsWrapper.setProps({ foo: 'abc', bar: 123 }) // @ts-expect-error :: should require string -propsWrapper.setProps({foo: 123}) +propsWrapper.setProps({ foo: 123 }) // @ts-expect-error :: unknown prop -propsWrapper.setProps({badProp: true}) +propsWrapper.setProps({ badProp: true }) expectType(propsWrapper.props().foo) expectType(propsWrapper.props().bar) // @ts-expect-error :: unknown prop -propsWrapper.props().badProp; +propsWrapper.props().badProp expectType(propsWrapper.props('foo')) expectType(propsWrapper.props('bar')) // @ts-expect-error :: unknown prop propsWrapper.props('badProp') + +const requiredPropsWrapper = mount( + defineComponent({ + props: { + foo: { type: String, required: true }, + bar: { type: Number, required: true } + } + }), + { + props: { + foo: 'abc', + bar: 123 + } + } +) + +requiredPropsWrapper.setProps({ + foo: 'abc' +}) + +requiredPropsWrapper.setProps({ + // @ts-expect-error wrong type + foo: 1 +})