Skip to content

Commit

Permalink
fix(runtime-core): custom-element: ensure event names are hyphenated
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusBorg committed Feb 8, 2022
1 parent 60cf175 commit 3d55f46
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions packages/runtime-dom/__tests__/customElement.spec.ts
Expand Up @@ -218,7 +218,10 @@ describe('defineCustomElement', () => {
emit('created')
return () =>
h('div', {
onClick: () => emit('my-click', 1)
onClick: () => {
emit('my-click', 1)
emit('myClick', 1) // validate hypenization
}
})
}
})
Expand All @@ -238,10 +241,13 @@ describe('defineCustomElement', () => {
const spy = jest.fn()
e.addEventListener('my-click', spy)
e.shadowRoot!.childNodes[0].dispatchEvent(new CustomEvent('click'))
expect(spy).toHaveBeenCalled()
expect(spy).toHaveBeenCalledTimes(2)
expect(spy.mock.calls[0][0]).toMatchObject({
detail: [1]
})
expect(spy.mock.calls[1][0]).toMatchObject({
detail: [1]
})
})
})

Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-dom/src/apiCustomElement.ts
Expand Up @@ -340,7 +340,7 @@ export class VueElement extends BaseClass {
// intercept emit
instance.emit = (event: string, ...args: any[]) => {
this.dispatchEvent(
new CustomEvent(event, {
new CustomEvent(hyphenate(event), {
detail: args
})
)
Expand Down

0 comments on commit 3d55f46

Please sign in to comment.