@@ -10,7 +10,11 @@ import {
10
10
Directive ,
11
11
Component ,
12
12
reactive ,
13
- ComponentPublicInstance
13
+ ComponentPublicInstance ,
14
+ ComponentOptionsWithObjectProps ,
15
+ ComponentOptionsWithArrayProps ,
16
+ ComponentOptionsWithoutProps ,
17
+ ExtractPropTypes
14
18
} from 'vue'
15
19
16
20
import { createWrapper , VueWrapper } from './vue-wrapper'
@@ -25,9 +29,9 @@ import { stubComponents } from './stubs'
25
29
26
30
type Slot = VNode | string | { render : Function }
27
31
28
- interface MountingOptions {
32
+ interface MountingOptions < Props > {
29
33
data ?: ( ) => Record < string , unknown >
30
- props ?: Record < string , any >
34
+ props ?: Props
31
35
slots ?: {
32
36
default ?: Slot
33
37
[ key : string ] : Slot
@@ -45,17 +49,41 @@ interface MountingOptions {
45
49
stubs ?: Record < string , any >
46
50
}
47
51
48
- export function mount < TestedComponent extends ComponentPublicInstance > (
52
+ // Component declared with defineComponent
53
+ export function mount <
54
+ TestedComponent extends ComponentPublicInstance ,
55
+ PublicProps extends TestedComponent [ '$props' ]
56
+ > (
49
57
originalComponent : new ( ) => TestedComponent ,
50
- options ?: MountingOptions
58
+ options ?: MountingOptions < PublicProps >
51
59
) : VueWrapper < TestedComponent >
52
- export function mount (
53
- originalComponent : Component ,
54
- options ?: MountingOptions
60
+ // Component declared with { props: { ... } }
61
+ export function mount <
62
+ TestedComponent extends ComponentOptionsWithObjectProps ,
63
+ PublicProps extends ExtractPropTypes < TestedComponent [ 'props' ] >
64
+ > (
65
+ originalComponent : TestedComponent ,
66
+ options ?: MountingOptions < PublicProps >
67
+ ) : VueWrapper < any >
68
+ // Component declared with { props: [] }
69
+ export function mount <
70
+ TestedComponent extends ComponentOptionsWithArrayProps ,
71
+ PublicProps extends Record < string , any >
72
+ > (
73
+ originalComponent : TestedComponent ,
74
+ options ?: MountingOptions < PublicProps >
75
+ ) : VueWrapper < any >
76
+ // Component declared with no props
77
+ export function mount <
78
+ TestedComponent extends ComponentOptionsWithoutProps ,
79
+ PublicProps extends Record < string , any >
80
+ > (
81
+ originalComponent : TestedComponent ,
82
+ options ?: MountingOptions < PublicProps >
55
83
) : VueWrapper < any >
56
84
export function mount (
57
85
originalComponent : any ,
58
- options ?: MountingOptions
86
+ options ?: MountingOptions < any >
59
87
) : VueWrapper < any > {
60
88
const component = { ...originalComponent }
61
89
0 commit comments