test: test for mixin/extends props merging

This commit is contained in:
Evan You 2020-06-09 16:20:33 -04:00
parent 2417a0cb30
commit 215c106297

View File

@ -6,7 +6,8 @@ import {
nodeOps, nodeOps,
FunctionalComponent, FunctionalComponent,
defineComponent, defineComponent,
ref ref,
serializeInner
} from '@vue/runtime-test' } from '@vue/runtime-test'
import { render as domRender, nextTick } from 'vue' import { render as domRender, nextTick } from 'vue'
import { mockWarn } from '@vue/shared' import { mockWarn } from '@vue/shared'
@ -259,4 +260,46 @@ describe('component props', () => {
}).toThrow(TypeError) }).toThrow(TypeError)
expect(`Attempting to mutate prop "foo"`).toHaveBeenWarned() expect(`Attempting to mutate prop "foo"`).toHaveBeenWarned()
}) })
test('merging props from mixins and extends', () => {
let setupProps: any
let renderProxy: any
const E = {
props: ['base']
}
const M1 = {
props: ['m1']
}
const M2 = {
props: { m2: null }
}
const Comp = {
props: ['self'],
mixins: [M1, M2],
extends: E,
setup(props: any) {
setupProps = props
},
render(this: any) {
renderProxy = this
return h('div', [this.self, this.base, this.m1, this.m2])
}
}
const root = nodeOps.createElement('div')
const props = {
self: 'from self, ',
base: 'from base, ',
m1: 'from mixin 1, ',
m2: 'from mixin 2'
}
render(h(Comp, props), root)
expect(serializeInner(root)).toMatch(
`from self, from base, from mixin 1, from mixin 2`
)
expect(setupProps).toMatchObject(props)
expect(renderProxy.$props).toMatchObject(props)
})
}) })