1
1
import { defineComponent , FunctionalComponent , h , SetupContext } from 'vue'
2
+ import { Vue } from 'vue-class-component'
2
3
3
4
import { mount } from '../src'
4
5
@@ -137,7 +138,7 @@ describe('emitted', () => {
137
138
expect ( wrapper . emitted ( 'hello' ) ) . toHaveLength ( 2 )
138
139
} )
139
140
140
- it ( 'gives a useful warning for functional components' , ( ) => {
141
+ it ( 'captures events emitted by functional components' , ( ) => {
141
142
const Component : FunctionalComponent <
142
143
{ bar : string ; level : number } ,
143
144
{ hello : ( foo : string , bar : string ) => void }
@@ -159,6 +160,24 @@ describe('emitted', () => {
159
160
expect ( wrapper . emitted ( 'hello' ) [ 0 ] ) . toEqual ( [ 'foo' , 'bar' ] )
160
161
} )
161
162
163
+ it ( 'captures events emitted by class-style components' , ( ) => {
164
+ // Define the component in class-style
165
+ class Component extends Vue {
166
+ bar = 'bar'
167
+ render ( ) {
168
+ return h ( `h1` , {
169
+ onClick : ( ) => this . $emit ( 'hello' , 'foo' , this . bar )
170
+ } )
171
+ }
172
+ }
173
+
174
+ const wrapper = mount ( Component , { } )
175
+
176
+ wrapper . find ( 'h1' ) . trigger ( 'click' )
177
+ expect ( wrapper . emitted ( 'hello' ) ) . toHaveLength ( 1 )
178
+ expect ( wrapper . emitted ( 'hello' ) [ 0 ] ) . toEqual ( [ 'foo' , 'bar' ] )
179
+ } )
180
+
162
181
it ( 'captures an event emitted in setup' , ( ) => {
163
182
const Comp = {
164
183
setup ( _ , { emit } ) {
0 commit comments