|
|
@@ -3,6 +3,7 @@
|
|
|
|
|
|
import {
|
|
|
type ComponentPublicInstance,
|
|
|
+ createApp,
|
|
|
defineComponent,
|
|
|
h,
|
|
|
nextTick,
|
|
|
@@ -598,4 +599,45 @@ describe('component: emit', () => {
|
|
|
render(h(ComponentC), el)
|
|
|
expect(renderFn).toHaveBeenCalledTimes(1)
|
|
|
})
|
|
|
+
|
|
|
+ test('merging emits for a component that is also used as a mixin', () => {
|
|
|
+ const render = () => h('div')
|
|
|
+ const CompA = {
|
|
|
+ render,
|
|
|
+ }
|
|
|
+ const validateByMixin = vi.fn(() => true)
|
|
|
+ const validateByGlobalMixin = vi.fn(() => true)
|
|
|
+
|
|
|
+ const mixin = {
|
|
|
+ emits: {
|
|
|
+ one: validateByMixin,
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ const CompB = defineComponent({
|
|
|
+ mixins: [mixin, CompA],
|
|
|
+ created(this) {
|
|
|
+ this.$emit('one', 1)
|
|
|
+ },
|
|
|
+ render,
|
|
|
+ })
|
|
|
+
|
|
|
+ const app = createApp({
|
|
|
+ render() {
|
|
|
+ return [h(CompA), h(CompB)]
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ app.mixin({
|
|
|
+ emits: {
|
|
|
+ one: validateByGlobalMixin,
|
|
|
+ two: null,
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ const root = nodeOps.createElement('div')
|
|
|
+ app.mount(root)
|
|
|
+ expect(validateByMixin).toHaveBeenCalledTimes(1)
|
|
|
+ expect(validateByGlobalMixin).not.toHaveBeenCalled()
|
|
|
+ })
|
|
|
})
|