UNPKG

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