onMousedown: () => {
emit('myEvent', 1) // validate hyphenation
},
+ onWheel: () => {
+ emit('my-wheel', { bubbles: true }, 1)
+ },
})
},
})
detail: [1],
})
})
+
// #7293
test('emit in an async component wrapper with properties bound', async () => {
const E = defineCustomElement(
detail: [1],
})
})
+
+ test('emit with options', async () => {
+ container.innerHTML = `<my-el-emits></my-el-emits>`
+ const e = container.childNodes[0] as VueElement
+ const spy = vi.fn()
+ e.addEventListener('my-wheel', spy)
+ e.shadowRoot!.childNodes[0].dispatchEvent(new CustomEvent('wheel'))
+ expect(spy).toHaveBeenCalledTimes(1)
+ expect(spy.mock.calls[0][0]).toMatchObject({
+ bubbles: true,
+ detail: [{ bubbles: true }, 1],
+ })
+ })
})
describe('slots', () => {
nextTick,
warn,
} from '@vue/runtime-core'
-import { camelize, extend, hyphenate, isArray, toNumber } from '@vue/shared'
+import {
+ camelize,
+ extend,
+ hyphenate,
+ isArray,
+ isPlainObject,
+ toNumber,
+} from '@vue/shared'
import { hydrate, render } from '.'
export type VueElementConstructor<P = {}> = {
const dispatch = (event: string, args: any[]) => {
this.dispatchEvent(
- new CustomEvent(event, {
- detail: args,
- }),
+ new CustomEvent(
+ event,
+ isPlainObject(args[0])
+ ? extend({ detail: args }, args[0])
+ : { detail: args },
+ ),
)
}