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 {
1010 ComponentOptionsWithoutProps ,
1111 ExtractPropTypes ,
1212 WritableComputedOptions ,
13- ComponentPropsOptions ,
1413 AppConfig ,
1514 VNodeProps ,
1615 ComponentOptionsMixin ,
@@ -21,7 +20,8 @@ import {
2120 ExtractDefaultPropTypes ,
2221 VNode ,
2322 EmitsOptions ,
24- ComputedOptions
23+ ComputedOptions ,
24+ ComponentPropsOptions
2525} from 'vue'
2626
2727import { MountingOptions , Slot } from './types'
@@ -337,6 +337,15 @@ export function mount(
337337 const Parent = defineComponent ( {
338338 name : MOUNT_PARENT_NAME ,
339339 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
340349 return h ( component , props , slots )
341350 }
342351 } )
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 66 SetupContext
77} from 'vue'
88import { Vue } from 'vue-class-component'
9+ import EmitsEventSFC from './components/EmitsEventSFC.vue'
10+ import EmitsEventScriptSetup from './components/EmitsEventScriptSetup.vue'
911
1012import { mount } from '../src'
1113
@@ -319,4 +321,17 @@ describe('emitted', () => {
319321 await wrapper . trigger ( 'click' )
320322 expect ( wrapper . emitted ( 'foo' ) ) . toHaveLength ( 1 )
321323 } )
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+ )
322337} )
You can’t perform that action at this time.
0 commit comments