@@ -3,34 +3,30 @@ import { ShapeFlags } from '@vue/shared'
3
3
4
4
import { config } from './config'
5
5
import { DOMWrapper } from './domWrapper'
6
- import {
7
- FindAllComponentsSelector ,
8
- FindComponentSelector ,
9
- VueWrapperMeta
10
- } from './types'
6
+ import { FindAllComponentsSelector , FindComponentSelector } from './types'
11
7
import { createWrapperError } from './errorWrapper'
12
8
import { TriggerOptions } from './createDomEvent'
13
9
import { find , matches } from './utils/find'
14
- import { isFunctionalComponent , mergeDeep } from './utils'
10
+ import { mergeDeep } from './utils'
15
11
16
12
export class VueWrapper < T extends ComponentPublicInstance > {
17
13
private componentVM : T
18
14
private rootVM : ComponentPublicInstance
19
15
private __app : App | null
20
16
private __setProps : ( ( props : Record < string , any > ) => void ) | undefined
21
- private __isFunctionalComponent : boolean
17
+ private __functionalEmits : Record < string , unknown [ ] >
22
18
23
19
constructor (
24
20
app : App | null ,
25
21
vm : ComponentPublicInstance ,
26
22
setProps ?: ( props : Record < string , any > ) => void ,
27
- meta ?: VueWrapperMeta
23
+ functionalEmits ?: Record < string , unknown [ ] >
28
24
) {
29
25
this . __app = app
30
26
this . rootVM = vm . $root !
31
27
this . componentVM = vm as T
32
28
this . __setProps = setProps
33
- this . __isFunctionalComponent = meta . isFunctionalComponent
29
+ this . __functionalEmits = functionalEmits
34
30
// plugins hook
35
31
config . plugins . VueWrapper . extend ( this )
36
32
}
@@ -79,12 +75,6 @@ export class VueWrapper<T extends ComponentPublicInstance> {
79
75
emitted < T = unknown > ( ) : Record < string , T [ ] >
80
76
emitted < T = unknown > ( eventName ?: string ) : T [ ]
81
77
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
-
88
78
if ( eventName ) {
89
79
const emitted = ( this . vm [ '__emitted' ] as Record < string , T [ ] > ) [ eventName ]
90
80
return emitted
@@ -151,27 +141,21 @@ export class VueWrapper<T extends ComponentPublicInstance> {
151
141
if ( typeof selector === 'object' && 'ref' in selector ) {
152
142
const result = this . vm . $refs [ selector . ref ]
153
143
if ( result ) {
154
- return createWrapper ( null , result as T , {
155
- isFunctionalComponent : isFunctionalComponent ( result )
156
- } )
144
+ return createWrapper ( null , result as T )
157
145
}
158
146
}
159
147
160
148
const result = find ( this . vm . $ . subTree , selector )
161
149
if ( result . length ) {
162
- return createWrapper ( null , result [ 0 ] , {
163
- isFunctionalComponent : isFunctionalComponent ( result )
164
- } )
150
+ return createWrapper ( null , result [ 0 ] )
165
151
}
166
152
167
153
// https://github.com/vuejs/vue-test-utils-next/issues/211
168
154
// VTU v1 supported finding the component mounted itself.
169
155
// eg: mount(Comp).findComponent(Comp)
170
156
// this is the same as doing `wrapper.vm`, but we keep this behavior for back compat.
171
157
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 )
175
159
}
176
160
177
161
return createWrapperError ( 'VueWrapper' )
@@ -207,11 +191,7 @@ export class VueWrapper<T extends ComponentPublicInstance> {
207
191
}
208
192
209
193
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 ) )
215
195
}
216
196
217
197
findAll < K extends keyof HTMLElementTagNameMap > (
@@ -266,8 +246,8 @@ export class VueWrapper<T extends ComponentPublicInstance> {
266
246
export function createWrapper < T extends ComponentPublicInstance > (
267
247
app : App | null ,
268
248
vm : ComponentPublicInstance ,
269
- meta : VueWrapperMeta ,
270
- setProps ?: ( props : Record < string , any > ) => void
249
+ setProps ?: ( props : Record < string , any > ) => void ,
250
+ functionalComponentEmits ?: Record < string , unknown [ ] >
271
251
) : VueWrapper < T > {
272
- return new VueWrapper < T > ( app , vm , setProps , meta )
252
+ return new VueWrapper < T > ( app , vm , setProps , functionalComponentEmits )
273
253
}
0 commit comments