From 0f696c5ad7ebe9ac72759cb197b58d6e0450e4a5 Mon Sep 17 00:00:00 2001 From: cexbrayat Date: Mon, 19 Apr 2021 17:50:35 +0200 Subject: [PATCH] fix: emits can be an object 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') })])