Skip to content

Commit fb92c07

Browse files
authored
fix: emits can be an object (#542)
The fix introduced in #521 only account for emits define as an array, but it can also be define as an object. The latest rc.5 release breaks on components that use an object to define emits with: TypeError: emits.includes is not a function This commit fixes the unit test to have both cases check, and the relevant code to properly handle the object case.
1 parent 9ffd586 commit fb92c07

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/vueWrapper.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,15 @@ export class VueWrapper<T extends ComponentPublicInstance>
5656
const vm = this.vm
5757
if (!vm) return
5858

59-
const emits = vm.$options.emits || []
59+
const emits = vm.$options.emits
60+
? // if emits is declared as an array
61+
Array.isArray(vm.$options.emits)
62+
? // use it
63+
vm.$options.emits
64+
: // otherwise it's declared as an object
65+
// and we only need the keys
66+
Object.keys(vm.$options.emits)
67+
: []
6068
const element = this.element
6169
for (let eventName of Object.keys(eventTypes)) {
6270
// if a component includes events in 'emits' with the same name as native

tests/emit.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ describe('emitted', () => {
137137
it('should not propagate child custom events', () => {
138138
const Child = defineComponent({
139139
name: 'Child',
140-
emits: ['hi'],
140+
emits: {
141+
hi: (foo: 'foo', bar: 'bar') => true
142+
},
141143
setup(props, { emit }) {
142144
return () =>
143145
h('div', [h('button', { onClick: () => emit('hi', 'foo', 'bar') })])

0 commit comments

Comments
 (0)