Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: emits can be an object #542

Merged
merged 1 commit into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/vueWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,15 @@ export class VueWrapper<T extends ComponentPublicInstance>
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
Expand Down
4 changes: 3 additions & 1 deletion tests/emit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') })])
Expand Down