From fb92c07d7ce834c10374d66bf3707656126e7f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Exbrayat?= Date: Mon, 19 Apr 2021 22:48:40 +0200 Subject: [PATCH] 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. --- src/vueWrapper.ts | 10 +++++++++- tests/emit.spec.ts | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/vueWrapper.ts b/src/vueWrapper.ts index 467621b61..c6ceb4cbf 100644 --- a/src/vueWrapper.ts +++ b/src/vueWrapper.ts @@ -56,7 +56,15 @@ export class VueWrapper const vm = this.vm if (!vm) return - const emits = vm.$options.emits || [] + const emits = vm.$options.emits + ? // if emits is declared as an array + Array.isArray(vm.$options.emits) + ? // use it + vm.$options.emits + : // otherwise it's declared as an object + // and we only need the keys + Object.keys(vm.$options.emits) + : [] const element = this.element for (let eventName of Object.keys(eventTypes)) { // if a component includes events in 'emits' with the same name as native diff --git a/tests/emit.spec.ts b/tests/emit.spec.ts index e8ec397d8..9862a3a90 100644 --- a/tests/emit.spec.ts +++ b/tests/emit.spec.ts @@ -137,7 +137,9 @@ describe('emitted', () => { it('should not propagate child custom events', () => { const Child = defineComponent({ name: 'Child', - emits: ['hi'], + emits: { + hi: (foo: 'foo', bar: 'bar') => true + }, setup(props, { emit }) { return () => h('div', [h('button', { onClick: () => emit('hi', 'foo', 'bar') })])