Skip to content

Commit 412c83f

Browse files
authored
Merge pull request #252 from vuejs/export-mounting-options
Export MountingOptions interface
2 parents 42762b9 + 08b6b28 commit 412c83f

File tree

3 files changed

+106
-26
lines changed

3 files changed

+106
-26
lines changed

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { mount, shallowMount } from './mount'
2+
import { MountingOptions } from './types'
23
import { RouterLinkStub } from './components/RouterLinkStub'
34
import { VueWrapper } from './vueWrapper'
45
import { DOMWrapper } from './domWrapper'
@@ -12,5 +13,6 @@ export {
1213
VueWrapper,
1314
DOMWrapper,
1415
config,
15-
flushPromises
16+
flushPromises,
17+
MountingOptions
1618
}

src/mount.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
h,
33
createApp,
4-
VNode,
54
defineComponent,
65
VNodeNormalizedChildren,
76
reactive,
@@ -11,7 +10,6 @@ import {
1110
ComponentOptionsWithArrayProps,
1211
ComponentOptionsWithoutProps,
1312
ExtractPropTypes,
14-
Component,
1513
WritableComputedOptions,
1614
ComponentPropsOptions,
1715
AppConfig,
@@ -25,9 +23,8 @@ import {
2523
} from 'vue'
2624

2725
import { config } from './config'
28-
import { GlobalMountOptions } from './types'
26+
import { MountingOptions, Slot } from './types'
2927
import {
30-
isClassComponent,
3128
isFunctionalComponent,
3229
isObjectComponent,
3330
mergeGlobalProperties
@@ -43,26 +40,6 @@ import { VueConstructor } from 'vue-class-component'
4340
// NOTE this should come from `vue`
4441
type PublicProps = VNodeProps & AllowedComponentProps & ComponentCustomProps
4542

46-
type Slot = VNode | string | { render: Function } | Function | Component
47-
48-
type SlotDictionary = {
49-
[key: string]: Slot
50-
}
51-
52-
interface MountingOptions<Props, Data = {}> {
53-
data?: () => {} extends Data ? any : Data extends object ? Partial<Data> : any
54-
props?: Props
55-
/** @deprecated */
56-
propsData?: Props
57-
attrs?: Record<string, unknown>
58-
slots?: SlotDictionary & {
59-
default?: Slot
60-
}
61-
global?: GlobalMountOptions
62-
attachTo?: HTMLElement | string
63-
shallow?: boolean
64-
}
65-
6643
export type ComputedOptions = Record<
6744
string,
6845
((ctx?: any) => any) | WritableComputedOptions<any>

src/types.ts

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { Component, ComponentOptions, Directive, Plugin, AppConfig } from 'vue'
1+
import {
2+
Component,
3+
ComponentOptions,
4+
Directive,
5+
Plugin,
6+
AppConfig,
7+
VNode
8+
} from 'vue'
29

310
interface RefSelector {
411
ref: string
@@ -19,14 +26,108 @@ interface NameSelector {
1926
export type FindComponentSelector = RefSelector | NameSelector | string
2027
export type FindAllComponentsSelector = NameSelector | string
2128

29+
export type Slot = VNode | string | { render: Function } | Function | Component
30+
31+
type SlotDictionary = {
32+
[key: string]: Slot
33+
}
34+
35+
export interface MountingOptions<Props, Data = {}> {
36+
/**
37+
* Overrides component's default data. Must be a function.
38+
* @see https://vue-test-utils.vuejs.org/v2/api/#data
39+
*/
40+
data?: () => {} extends Data ? any : Data extends object ? Partial<Data> : any
41+
/**
42+
* Sets component props when mounted.
43+
* @see https://vue-test-utils.vuejs.org/v2/api/#props
44+
*/
45+
props?: Props
46+
/**
47+
* @deprecated use `data` instead.
48+
*/
49+
propsData?: Props
50+
/**
51+
* Sets component attributes when mounted.
52+
* @see https://vue-test-utils.vuejs.org/v2/api/#attrs
53+
*/
54+
attrs?: Record<string, unknown>
55+
/**
56+
* Provide values for slots on a component. Slots can be a component
57+
* imported from a .vue file or a render function. Providing an
58+
* object with a `template` key is not supported.
59+
* @see https://vue-test-utils.vuejs.org/v2/api/#slots
60+
*/
61+
slots?: SlotDictionary & {
62+
default?: Slot
63+
}
64+
/**
65+
* Provides global mounting options to the component.
66+
*/
67+
global?: GlobalMountOptions
68+
/**
69+
* Specify where to mount the component.
70+
* Can be a valid CSS selector, or an Element connected to the document.
71+
* @see https://vue-test-utils.vuejs.org/v2/api/#attachto
72+
*/
73+
attachTo?: HTMLElement | string
74+
/**
75+
* Automatically stub out all the child components.
76+
* @default false
77+
* @see https://vue-test-utils.vuejs.org/v2/api/#slots
78+
*/
79+
shallow?: boolean
80+
}
81+
2282
export type GlobalMountOptions = {
83+
/**
84+
* Installs plugins on the component.
85+
* @see https://vue-test-utils.vuejs.org/v2/api/#plugins
86+
*/
2387
plugins?: (Plugin | [Plugin, ...any[]])[]
88+
/**
89+
* Customizes Vue application global configuration
90+
* @see https://v3.vuejs.org/api/application-config.html#application-config
91+
*/
2492
config?: Partial<Omit<AppConfig, 'isNativeTag'>> // isNativeTag is readonly, so we omit it
93+
/**
94+
* Applies a mixin for components under testing.
95+
* @see https://vue-test-utils.vuejs.org/v2/api/#mixins
96+
*/
2597
mixins?: ComponentOptions[]
98+
/**
99+
* Mocks a global instance property.
100+
* This is designed to mock variables injected by third party plugins, not
101+
* Vue's native properties such as $root, $children, etc.
102+
* @see https://vue-test-utils.vuejs.org/v2/api/#mocks
103+
*/
26104
mocks?: Record<string, any>
105+
/**
106+
* Provides data to be received in a setup function via `inject`.
107+
* @see https://vue-test-utils.vuejs.org/v2/api/#provide
108+
*/
27109
provide?: Record<any, any>
110+
/**
111+
* Registers components globally for components under testing.
112+
* @see https://vue-test-utils.vuejs.org/v2/api/#components
113+
*/
28114
components?: Record<string, Component | object>
115+
/**
116+
* Registers a directive globally for components under testing
117+
* @see https://vue-test-utils.vuejs.org/v2/api/#directives
118+
*/
29119
directives?: Record<string, Directive>
120+
/**
121+
* Stubs a component for components under testing.
122+
* @default "{ transition: true, 'transition-group': true }"
123+
* @see https://vue-test-utils.vuejs.org/v2/api/#global-stubs
124+
*/
30125
stubs?: Record<any, any>
126+
/**
127+
* Allows rendering the default slot content, even when using
128+
* `shallow` or `shallowMount`.
129+
* @default false
130+
* @see https://vue-test-utils.vuejs.org/v2/api/#renderstubdefaultslot
131+
*/
31132
renderStubDefaultSlot?: boolean
32133
}

0 commit comments

Comments
 (0)