diff --git a/src/index.ts b/src/index.ts index 5f19a9ce3..00dba642e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ import { mount, shallowMount } from './mount' +import { MountingOptions } from './types' import { RouterLinkStub } from './components/RouterLinkStub' import { VueWrapper } from './vueWrapper' import { DOMWrapper } from './domWrapper' @@ -12,5 +13,6 @@ export { VueWrapper, DOMWrapper, config, - flushPromises + flushPromises, + MountingOptions } diff --git a/src/mount.ts b/src/mount.ts index 684d39f2e..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,9 +23,8 @@ import { } from 'vue' import { config } from './config' -import { GlobalMountOptions } from './types' +import { MountingOptions, Slot } from './types' import { - isClassComponent, isFunctionalComponent, isObjectComponent, mergeGlobalProperties @@ -43,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 -} - -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 }