Skip to content

Commit 08b6b28

Browse files
committed
Add docs to exported types
1 parent 1078ec9 commit 08b6b28

File tree

3 files changed

+105
-25
lines changed

3 files changed

+105
-25
lines changed

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { mount, shallowMount, MountingOptions } from './mount'
1+
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'

src/mount.ts

Lines changed: 1 addition & 23 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,7 +23,7 @@ import {
2523
} from 'vue'
2624

2725
import { config } from './config'
28-
import { GlobalMountOptions } from './types'
26+
import { MountingOptions, Slot } from './types'
2927
import {
3028
isFunctionalComponent,
3129
isObjectComponent,
@@ -42,26 +40,6 @@ import { VueConstructor } from 'vue-class-component'
4240
// NOTE this should come from `vue`
4341
type PublicProps = VNodeProps & AllowedComponentProps & ComponentCustomProps
4442

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