@@ -3,34 +3,30 @@ import { ShapeFlags } from '@vue/shared'
33
44import { config } from './config'
55import { DOMWrapper } from './domWrapper'
6- import {
7- FindAllComponentsSelector ,
8- FindComponentSelector ,
9- VueWrapperMeta
10- } from './types'
6+ import { FindAllComponentsSelector , FindComponentSelector } from './types'
117import { createWrapperError } from './errorWrapper'
128import { TriggerOptions } from './createDomEvent'
139import { find , matches } from './utils/find'
14- import { isFunctionalComponent , mergeDeep } from './utils'
10+ import { mergeDeep } from './utils'
1511
1612export class VueWrapper < T extends ComponentPublicInstance > {
1713 private componentVM : T
1814 private rootVM : ComponentPublicInstance
1915 private __app : App | null
2016 private __setProps : ( ( props : Record < string , any > ) => void ) | undefined
21- private __isFunctionalComponent : boolean
17+ private __functionalEmits : Record < string , unknown [ ] >
2218
2319 constructor (
2420 app : App | null ,
2521 vm : ComponentPublicInstance ,
2622 setProps ?: ( props : Record < string , any > ) => void ,
27- meta ?: VueWrapperMeta
23+ functionalEmits ?: Record < string , unknown [ ] >
2824 ) {
2925 this . __app = app
3026 this . rootVM = vm . $root !
3127 this . componentVM = vm as T
3228 this . __setProps = setProps
33- this . __isFunctionalComponent = meta . isFunctionalComponent
29+ this . __functionalEmits = functionalEmits
3430 // plugins hook
3531 config . plugins . VueWrapper . extend ( this )
3632 }
@@ -79,12 +75,6 @@ export class VueWrapper<T extends ComponentPublicInstance> {
7975 emitted < T = unknown > ( ) : Record < string , T [ ] >
8076 emitted < T = unknown > ( eventName ?: string ) : T [ ]
8177 emitted < T = unknown > ( eventName ?: string ) : T [ ] | Record < string , T [ ] > {
82- if ( this . __isFunctionalComponent ) {
83- console . warn (
84- '[Vue Test Utils]: capture events emitted from functional components is currently not supported.'
85- )
86- }
87-
8878 if ( eventName ) {
8979 const emitted = ( this . vm [ '__emitted' ] as Record < string , T [ ] > ) [ eventName ]
9080 return emitted
@@ -151,27 +141,21 @@ export class VueWrapper<T extends ComponentPublicInstance> {
151141 if ( typeof selector === 'object' && 'ref' in selector ) {
152142 const result = this . vm . $refs [ selector . ref ]
153143 if ( result ) {
154- return createWrapper ( null , result as T , {
155- isFunctionalComponent : isFunctionalComponent ( result )
156- } )
144+ return createWrapper ( null , result as T )
157145 }
158146 }
159147
160148 const result = find ( this . vm . $ . subTree , selector )
161149 if ( result . length ) {
162- return createWrapper ( null , result [ 0 ] , {
163- isFunctionalComponent : isFunctionalComponent ( result )
164- } )
150+ return createWrapper ( null , result [ 0 ] )
165151 }
166152
167153 // https://github.com/vuejs/vue-test-utils-next/issues/211
168154 // VTU v1 supported finding the component mounted itself.
169155 // eg: mount(Comp).findComponent(Comp)
170156 // this is the same as doing `wrapper.vm`, but we keep this behavior for back compat.
171157 if ( matches ( this . vm . $ . vnode , selector ) ) {
172- return createWrapper ( null , this . vm . $ . vnode . component . proxy , {
173- isFunctionalComponent : false
174- } )
158+ return createWrapper ( null , this . vm . $ . vnode . component . proxy )
175159 }
176160
177161 return createWrapperError ( 'VueWrapper' )
@@ -207,11 +191,7 @@ export class VueWrapper<T extends ComponentPublicInstance> {
207191 }
208192
209193 findAllComponents ( selector : FindAllComponentsSelector ) : VueWrapper < T > [ ] {
210- return find ( this . vm . $ . subTree , selector ) . map ( ( c ) =>
211- createWrapper ( null , c , {
212- isFunctionalComponent : isFunctionalComponent ( c )
213- } )
214- )
194+ return find ( this . vm . $ . subTree , selector ) . map ( ( c ) => createWrapper ( null , c ) )
215195 }
216196
217197 findAll < K extends keyof HTMLElementTagNameMap > (
@@ -266,8 +246,8 @@ export class VueWrapper<T extends ComponentPublicInstance> {
266246export function createWrapper < T extends ComponentPublicInstance > (
267247 app : App | null ,
268248 vm : ComponentPublicInstance ,
269- meta : VueWrapperMeta ,
270- setProps ?: ( props : Record < string , any > ) => void
249+ setProps ?: ( props : Record < string , any > ) => void ,
250+ functionalComponentEmits ?: Record < string , unknown [ ] >
271251) : VueWrapper < T > {
272- return new VueWrapper < T > ( app , vm , setProps , meta )
252+ return new VueWrapper < T > ( app , vm , setProps , functionalComponentEmits )
273253}
0 commit comments