Skip to content

Commit dc4bac4

Browse files
gcaaa319289romise
authored andcommitted
fix(runtime-core): use separate emits caches for components and mixins (#11661)
1 parent adf19f2 commit dc4bac4

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

packages/runtime-core/__tests__/componentEmits.spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import {
55
type ComponentPublicInstance,
6+
createApp,
67
defineComponent,
78
h,
89
nextTick,
@@ -598,4 +599,45 @@ describe('component: emit', () => {
598599
render(h(ComponentC), el)
599600
expect(renderFn).toHaveBeenCalledTimes(1)
600601
})
602+
603+
test('merging emits for a component that is also used as a mixin', () => {
604+
const render = () => h('div')
605+
const CompA = {
606+
render,
607+
}
608+
const validateByMixin = vi.fn(() => true)
609+
const validateByGlobalMixin = vi.fn(() => true)
610+
611+
const mixin = {
612+
emits: {
613+
one: validateByMixin,
614+
},
615+
}
616+
617+
const CompB = defineComponent({
618+
mixins: [mixin, CompA],
619+
created(this) {
620+
this.$emit('one', 1)
621+
},
622+
render,
623+
})
624+
625+
const app = createApp({
626+
render() {
627+
return [h(CompA), h(CompB)]
628+
},
629+
})
630+
631+
app.mixin({
632+
emits: {
633+
one: validateByGlobalMixin,
634+
two: null,
635+
},
636+
})
637+
638+
const root = nodeOps.createElement('div')
639+
app.mount(root)
640+
expect(validateByMixin).toHaveBeenCalledTimes(1)
641+
expect(validateByGlobalMixin).not.toHaveBeenCalled()
642+
})
601643
})

0 commit comments

Comments
 (0)