forked from vuejs/test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
169 lines (157 loc) · 4.67 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import {
Component,
ComponentOptions,
Directive,
Plugin,
AppConfig,
VNode,
VNodeProps,
FunctionalComponent,
ComponentInternalInstance
} from 'vue'
export interface RefSelector {
ref: string
}
export interface NameSelector {
name: string
length?: never
}
export type FindAllComponentsSelector =
| DefinedComponent
| FunctionalComponent
| ComponentOptions
| NameSelector
| string
export type FindComponentSelector = RefSelector | FindAllComponentsSelector
export type Slot = VNode | string | { render: Function } | Function | Component
type SlotDictionary = {
[key: string]: Slot
}
// From vue next
// https://github.com/vuejs/vue-next/blob/1f2a652a9d2e3bec472fb1786a4c16d6ccfa1fb1/packages/runtime-core/src/h.ts#L53-L58
type RawProps = VNodeProps & {
// used to differ from a single VNode object as children
__v_isVNode?: never
// used to differ from Array children
[Symbol.iterator]?: never
} & Record<string, any>
interface BaseMountingOptions<Props, Data = {}> {
/**
* Overrides component's default data. Must be a function.
* @see https://test-utils.vuejs.org/api/#data
*/
data?: () => {} extends Data ? any : Data extends object ? Partial<Data> : any
/**
* Sets component props when mounted.
* @see https://test-utils.vuejs.org/api/#props
*/
props?: (RawProps & Props) | ({} extends Props ? null : never)
/**
* @deprecated use `props` instead.
*/
propsData?: Props
/**
* Sets component attributes when mounted.
* @see https://test-utils.vuejs.org/api/#attrs
*/
attrs?: Record<string, unknown>
/**
* Provide values for slots on a component.
* @see https://test-utils.vuejs.org/api/#slots
*/
slots?: SlotDictionary & {
default?: Slot
}
/**
* Provides global mounting options to the component.
*/
global?: GlobalMountOptions
/**
* Automatically stub out all the child components.
* @default false
* @see https://test-utils.vuejs.org/api/#slots
*/
shallow?: boolean
}
/**
* Mounting options for `mount` and `shallowMount`
*/
export interface MountingOptions<Props, Data = {}>
extends BaseMountingOptions<Props, Data> {
/**
* Specify where to mount the component.
* Can be a valid CSS selector, or an Element connected to the document.
* @see https://test-utils.vuejs.org/api/#attachto
*/
attachTo?: HTMLElement | string
}
/**
* Mounting options for `renderToString`
*/
export interface RenderMountingOptions<Props, Data = {}>
extends BaseMountingOptions<Props, Data> {
/**
* Attach to is not available in SSR mode
*/
attachTo?: never
}
export type Stub = boolean | Component | Directive
export type Stubs = Record<string, Stub> | Array<string>
export type GlobalMountOptions = {
/**
* Installs plugins on the component.
* @see https://test-utils.vuejs.org/api/#global-plugins
*/
plugins?: (Plugin | [Plugin, ...any[]])[]
/**
* Customizes Vue application global configuration
* @see https://v3.vuejs.org/api/application-config.html#application-config
*/
config?: Partial<Omit<AppConfig, 'isNativeTag'>> // isNativeTag is readonly, so we omit it
/**
* Applies a mixin for components under testing.
* @see https://test-utils.vuejs.org/api/#global-mixins
*/
mixins?: ComponentOptions[]
/**
* Mocks a global instance property.
* This is designed to mock variables injected by third party plugins, not
* Vue's native properties such as $root, $children, etc.
* @see https://test-utils.vuejs.org/api/#global-mocks
*/
mocks?: Record<string, any>
/**
* Provides data to be received in a setup function via `inject`.
* @see https://test-utils.vuejs.org/api/#global-provide
*/
provide?: Record<any, any>
/**
* Registers components globally for components under testing.
* @see https://test-utils.vuejs.org/api/#global-components
*/
components?: Record<string, Component | object>
/**
* Registers a directive globally for components under testing
* @see https://test-utils.vuejs.org/api/#global-directives
*/
directives?: Record<string, Directive>
/**
* Stubs a component for components under testing.
* @default "{ transition: true, 'transition-group': true }"
* @see https://test-utils.vuejs.org/api/#global-stubs
*/
stubs?: Stubs
/**
* Allows rendering the default slot content, even when using
* `shallow` or `shallowMount`.
* @default false
* @see https://test-utils.vuejs.org/api/#global-renderstubdefaultslot
*/
renderStubDefaultSlot?: boolean
}
export type VueNode<T extends Node = Node> = T & {
__vue_app__?: any
__vueParentComponent?: ComponentInternalInstance
}
export type VueElement = VueNode<Element>
export type DefinedComponent = new (...args: any[]) => any