Skip to content

Commit 593c6d0

Browse files
committed
improve mount of functionalComponent and add couple more tests
1 parent 3caf178 commit 593c6d0

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

src/mount.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,36 +64,20 @@ export type ObjectEmitsOptions = Record<
6464
export type EmitsOptions = ObjectEmitsOptions | string[]
6565

6666
// Functional component
67-
export function mount<TestedComponent extends FunctionalComponent>(
67+
export function mount<
68+
TestedComponent extends FunctionalComponent<Props>,
69+
Props
70+
>(
6871
originalComponent: TestedComponent,
69-
options?: MountingOptions<any>
70-
): VueWrapper<ComponentPublicInstance>
72+
options?: MountingOptions<Props>
73+
): VueWrapper<ComponentPublicInstance<Props>>
74+
7175
// Component declared with defineComponent
7276
export function mount<TestedComponent extends ComponentPublicInstance>(
7377
originalComponent: { new (): TestedComponent } & Component,
7478
options?: MountingOptions<TestedComponent['$props'], TestedComponent['$data']>
7579
): VueWrapper<TestedComponent>
7680

77-
// Functional Component declared with (props, ctx)=> render
78-
export function mount<Props, RawBindings = object>(
79-
setup: (
80-
props: Readonly<Props>,
81-
ctx: SetupContext
82-
) => RawBindings | RenderFunction,
83-
84-
options: MountingOptions<Props, {}>
85-
): VueWrapper<
86-
ComponentPublicInstance<
87-
Props,
88-
RawBindings,
89-
{},
90-
{},
91-
{},
92-
// public props
93-
VNodeProps & Props
94-
>
95-
>
96-
9781
// Component declared with no props
9882
export function mount<
9983
Props = {},

test-dts/mount.d-test.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,11 @@ expectType<string>(
9191

9292
// can receive extra props
9393
// as they are declared as `string[]`
94-
mount(AppWithArrayProps, {
95-
props: { a: 'Hello', b: 2 }
96-
})
94+
expectType<number>(
95+
mount(AppWithArrayProps, {
96+
props: { a: 'Hello', b: 2 }
97+
}).vm.b
98+
)
9799

98100
// cannot receive extra props
99101
// if they pass use object inside
@@ -125,3 +127,20 @@ expectError(
125127
mount(AppWithoutProps, {
126128
props: { b: 'Hello' } as never
127129
})
130+
131+
// Functional tests
132+
133+
// wrong props
134+
expectError((props: { a: 1 }) => {}, {
135+
props: {
136+
a: '222'
137+
}
138+
})
139+
140+
expectType<number>(
141+
mount((props: { a: 1 }, ctx) => {}, {
142+
props: {
143+
a: 22
144+
}
145+
}).vm.a
146+
)

0 commit comments

Comments
 (0)