From 87474dc9be6ac3a799c6075c7d9cb87d8aa74083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Fontcuberta?= Date: Sat, 21 Nov 2020 00:43:39 +0100 Subject: [PATCH 1/3] Export MountingOptions --- src/index.ts | 5 +++-- src/mount.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5f19a9ce3..194058f06 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import { mount, shallowMount } from './mount' +import { mount, shallowMount, MountingOptions } from './mount' import { RouterLinkStub } from './components/RouterLinkStub' import { VueWrapper } from './vueWrapper' import { DOMWrapper } from './domWrapper' @@ -12,5 +12,6 @@ export { VueWrapper, DOMWrapper, config, - flushPromises + flushPromises, + MountingOptions } diff --git a/src/mount.ts b/src/mount.ts index 684d39f2e..3d5168b8a 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -49,7 +49,7 @@ type SlotDictionary = { [key: string]: Slot } -interface MountingOptions { +export interface MountingOptions { data?: () => {} extends Data ? any : Data extends object ? Partial : any props?: Props /** @deprecated */ From 1078ec9a136a24f8948e3ca4a746bc83ff825bb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Fontcuberta?= Date: Sat, 21 Nov 2020 00:44:17 +0100 Subject: [PATCH 2/3] Remove unused import --- src/mount.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mount.ts b/src/mount.ts index 3d5168b8a..eb4c19b7d 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -27,7 +27,6 @@ import { import { config } from './config' import { GlobalMountOptions } from './types' import { - isClassComponent, isFunctionalComponent, isObjectComponent, mergeGlobalProperties From 08b6b28346574b5eb3529fece27e50da480183e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Fontcuberta?= Date: Sun, 22 Nov 2020 10:11:34 +0100 Subject: [PATCH 3/3] Add docs to exported types --- src/index.ts | 3 +- src/mount.ts | 24 +----------- src/types.ts | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 105 insertions(+), 25 deletions(-) diff --git a/src/index.ts b/src/index.ts index 194058f06..00dba642e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ -import { mount, shallowMount, MountingOptions } from './mount' +import { mount, shallowMount } from './mount' +import { MountingOptions } from './types' import { RouterLinkStub } from './components/RouterLinkStub' import { VueWrapper } from './vueWrapper' import { DOMWrapper } from './domWrapper' diff --git a/src/mount.ts b/src/mount.ts index eb4c19b7d..c905a99ea 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -1,7 +1,6 @@ import { h, createApp, - VNode, defineComponent, VNodeNormalizedChildren, reactive, @@ -11,7 +10,6 @@ import { ComponentOptionsWithArrayProps, ComponentOptionsWithoutProps, ExtractPropTypes, - Component, WritableComputedOptions, ComponentPropsOptions, AppConfig, @@ -25,7 +23,7 @@ import { } from 'vue' import { config } from './config' -import { GlobalMountOptions } from './types' +import { MountingOptions, Slot } from './types' import { isFunctionalComponent, isObjectComponent, @@ -42,26 +40,6 @@ import { VueConstructor } from 'vue-class-component' // NOTE this should come from `vue` type PublicProps = VNodeProps & AllowedComponentProps & ComponentCustomProps -type Slot = VNode | string | { render: Function } | Function | Component - -type SlotDictionary = { - [key: string]: Slot -} - -export interface MountingOptions { - data?: () => {} extends Data ? any : Data extends object ? Partial : any - props?: Props - /** @deprecated */ - propsData?: Props - attrs?: Record - slots?: SlotDictionary & { - default?: Slot - } - global?: GlobalMountOptions - attachTo?: HTMLElement | string - shallow?: boolean -} - export type ComputedOptions = Record< string, ((ctx?: any) => any) | WritableComputedOptions diff --git a/src/types.ts b/src/types.ts index 136d938f5..5ca8dc36a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,11 @@ -import { Component, ComponentOptions, Directive, Plugin, AppConfig } from 'vue' +import { + Component, + ComponentOptions, + Directive, + Plugin, + AppConfig, + VNode +} from 'vue' interface RefSelector { ref: string @@ -19,14 +26,108 @@ interface NameSelector { export type FindComponentSelector = RefSelector | NameSelector | string export type FindAllComponentsSelector = NameSelector | string +export type Slot = VNode | string | { render: Function } | Function | Component + +type SlotDictionary = { + [key: string]: Slot +} + +export interface MountingOptions { + /** + * Overrides component's default data. Must be a function. + * @see https://vue-test-utils.vuejs.org/v2/api/#data + */ + data?: () => {} extends Data ? any : Data extends object ? Partial : any + /** + * Sets component props when mounted. + * @see https://vue-test-utils.vuejs.org/v2/api/#props + */ + props?: Props + /** + * @deprecated use `data` instead. + */ + propsData?: Props + /** + * Sets component attributes when mounted. + * @see https://vue-test-utils.vuejs.org/v2/api/#attrs + */ + attrs?: Record + /** + * Provide values for slots on a component. Slots can be a component + * imported from a .vue file or a render function. Providing an + * object with a `template` key is not supported. + * @see https://vue-test-utils.vuejs.org/v2/api/#slots + */ + slots?: SlotDictionary & { + default?: Slot + } + /** + * Provides global mounting options to the component. + */ + global?: GlobalMountOptions + /** + * Specify where to mount the component. + * Can be a valid CSS selector, or an Element connected to the document. + * @see https://vue-test-utils.vuejs.org/v2/api/#attachto + */ + attachTo?: HTMLElement | string + /** + * Automatically stub out all the child components. + * @default false + * @see https://vue-test-utils.vuejs.org/v2/api/#slots + */ + shallow?: boolean +} + export type GlobalMountOptions = { + /** + * Installs plugins on the component. + * @see https://vue-test-utils.vuejs.org/v2/api/#plugins + */ plugins?: (Plugin | [Plugin, ...any[]])[] + /** + * Customizes Vue application global configuration + * @see https://v3.vuejs.org/api/application-config.html#application-config + */ config?: Partial> // isNativeTag is readonly, so we omit it + /** + * Applies a mixin for components under testing. + * @see https://vue-test-utils.vuejs.org/v2/api/#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://vue-test-utils.vuejs.org/v2/api/#mocks + */ mocks?: Record + /** + * Provides data to be received in a setup function via `inject`. + * @see https://vue-test-utils.vuejs.org/v2/api/#provide + */ provide?: Record + /** + * Registers components globally for components under testing. + * @see https://vue-test-utils.vuejs.org/v2/api/#components + */ components?: Record + /** + * Registers a directive globally for components under testing + * @see https://vue-test-utils.vuejs.org/v2/api/#directives + */ directives?: Record + /** + * Stubs a component for components under testing. + * @default "{ transition: true, 'transition-group': true }" + * @see https://vue-test-utils.vuejs.org/v2/api/#global-stubs + */ stubs?: Record + /** + * Allows rendering the default slot content, even when using + * `shallow` or `shallowMount`. + * @default false + * @see https://vue-test-utils.vuejs.org/v2/api/#renderstubdefaultslot + */ renderStubDefaultSlot?: boolean }