Skip to content

Commit

Permalink
test: test for mixin/extends props merging
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 9, 2020
1 parent 2417a0c commit 215c106
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion packages/runtime-core/__tests__/componentProps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
nodeOps,
FunctionalComponent,
defineComponent,
ref
ref,
serializeInner
} from '@vue/runtime-test'
import { render as domRender, nextTick } from 'vue'
import { mockWarn } from '@vue/shared'
Expand Down Expand Up @@ -259,4 +260,46 @@ describe('component props', () => {
}).toThrow(TypeError)
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)
})
})

0 comments on commit 215c106

Please sign in to comment.