File tree Expand file tree Collapse file tree 4 files changed +62
-2
lines changed Expand file tree Collapse file tree 4 files changed +62
-2
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ import {
10
10
ComponentOptionsWithoutProps ,
11
11
ExtractPropTypes ,
12
12
WritableComputedOptions ,
13
- ComponentPropsOptions ,
14
13
AppConfig ,
15
14
VNodeProps ,
16
15
ComponentOptionsMixin ,
@@ -21,7 +20,8 @@ import {
21
20
ExtractDefaultPropTypes ,
22
21
VNode ,
23
22
EmitsOptions ,
24
- ComputedOptions
23
+ ComputedOptions ,
24
+ ComponentPropsOptions
25
25
} from 'vue'
26
26
27
27
import { MountingOptions , Slot } from './types'
@@ -337,6 +337,15 @@ export function mount(
337
337
const Parent = defineComponent ( {
338
338
name : MOUNT_PARENT_NAME ,
339
339
render ( ) {
340
+ // https://github.com/vuejs/vue-test-utils-next/issues/651
341
+ // script setup components include an empty `expose` array as part of the
342
+ // code generated by the SFC compiler. Eg a component might look like
343
+ // { expose: [], setup: [Function], render: [Function] }
344
+ // not sure why (yet), but the empty expose array causes events to not be
345
+ // correctly captured.
346
+ // TODO: figure out why this is happening and understand the implications of
347
+ // the expose rfc for Test Utils.
348
+ delete component . expose
340
349
return h ( component , props , slots )
341
350
}
342
351
} )
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <button @click =" click" />
3
+ </template >
4
+
5
+ <script lang="ts">
6
+ import { defineComponent , onMounted } from ' vue' ;
7
+
8
+ export default defineComponent ({
9
+ emits: [' bar' ],
10
+ setup(props , { emit }) {
11
+ onMounted (() => {
12
+ emit (' bar' , ' mounted' )
13
+ })
14
+
15
+ return {
16
+ click : () => emit (' bar' , ' click' )
17
+ }
18
+ }
19
+ })
20
+
21
+ </script >
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <button @click =" click" />
3
+ </template >
4
+
5
+ <script setup lang="ts">
6
+ import { onMounted , defineEmit } from ' vue' ;
7
+
8
+ const emit = defineEmit ([' bar' ]);
9
+
10
+ const click = () => emit (' bar' , ' click' )
11
+
12
+ onMounted (() => {
13
+ emit (' bar' , ' mounted' )
14
+ })
15
+ </script >
Original file line number Diff line number Diff line change 6
6
SetupContext
7
7
} from 'vue'
8
8
import { Vue } from 'vue-class-component'
9
+ import EmitsEventSFC from './components/EmitsEventSFC.vue'
10
+ import EmitsEventScriptSetup from './components/EmitsEventScriptSetup.vue'
9
11
10
12
import { mount } from '../src'
11
13
@@ -319,4 +321,17 @@ describe('emitted', () => {
319
321
await wrapper . trigger ( 'click' )
320
322
expect ( wrapper . emitted ( 'foo' ) ) . toHaveLength ( 1 )
321
323
} )
324
+
325
+ it . each ( [ EmitsEventSFC , EmitsEventScriptSetup ] ) (
326
+ 'captures emitted events' ,
327
+ async ( component ) => {
328
+ const wrapper = mount ( component )
329
+ await wrapper . trigger ( 'click' )
330
+
331
+ expect ( wrapper . emitted ( ) . click ) . toHaveLength ( 1 )
332
+ expect ( wrapper . emitted ( ) . bar ) . toHaveLength ( 2 )
333
+ expect ( wrapper . emitted ( ) . bar [ 0 ] ) . toEqual ( [ 'mounted' ] )
334
+ expect ( wrapper . emitted ( ) . bar [ 1 ] ) . toEqual ( [ 'click' ] )
335
+ }
336
+ )
322
337
} )
You can’t perform that action at this time.
0 commit comments