Skip to content

Commit

Permalink
Merge pull request #252 from vuejs/export-mounting-options
Browse files Browse the repository at this point in the history
Export MountingOptions interface
  • Loading branch information
lmiller1990 committed Nov 22, 2020
2 parents 42762b9 + 08b6b28 commit 412c83f
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 26 deletions.
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -12,5 +13,6 @@ export {
VueWrapper,
DOMWrapper,
config,
flushPromises
flushPromises,
MountingOptions
}
25 changes: 1 addition & 24 deletions src/mount.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
h,
createApp,
VNode,
defineComponent,
VNodeNormalizedChildren,
reactive,
Expand All @@ -11,7 +10,6 @@ import {
ComponentOptionsWithArrayProps,
ComponentOptionsWithoutProps,
ExtractPropTypes,
Component,
WritableComputedOptions,
ComponentPropsOptions,
AppConfig,
Expand All @@ -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
Expand All @@ -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<Props, Data = {}> {
data?: () => {} extends Data ? any : Data extends object ? Partial<Data> : any
props?: Props
/** @deprecated */
propsData?: Props
attrs?: Record<string, unknown>
slots?: SlotDictionary & {
default?: Slot
}
global?: GlobalMountOptions
attachTo?: HTMLElement | string
shallow?: boolean
}

export type ComputedOptions = Record<
string,
((ctx?: any) => any) | WritableComputedOptions<any>
Expand Down
103 changes: 102 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<Props, Data = {}> {
/**
* 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<Data> : 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<string, unknown>
/**
* 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<Omit<AppConfig, 'isNativeTag'>> // 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<string, any>
/**
* Provides data to be received in a setup function via `inject`.
* @see https://vue-test-utils.vuejs.org/v2/api/#provide
*/
provide?: Record<any, any>
/**
* Registers components globally for components under testing.
* @see https://vue-test-utils.vuejs.org/v2/api/#components
*/
components?: Record<string, Component | object>
/**
* Registers a directive globally for components under testing
* @see https://vue-test-utils.vuejs.org/v2/api/#directives
*/
directives?: Record<string, Directive>
/**
* 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<any, any>
/**
* 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
}

0 comments on commit 412c83f

Please sign in to comment.