test: improve tests and typing for runtime-core (#100)

* test: add test case for declaring Array prop type with constructor casting in `createComponent`

* test: add test case for `setup(props)` with explicit props declaration
This commit is contained in:
Carlos Rodrigues
2019-10-05 20:37:55 +01:00
committed by Evan You
parent f48a2ffc76
commit 8133b3867a
4 changed files with 46 additions and 6 deletions

View File

@@ -74,6 +74,39 @@ describe('api: setup context', () => {
expect(dummy).toBe(1)
})
it('setup props should resolve the correct types from props object', async () => {
const count = ref(0)
let dummy
const Parent = {
render: () => h(Child, { count: count.value })
}
const Child = createComponent({
props: {
count: Number
},
setup(props) {
watch(() => {
dummy = props.count
})
return () => h('div', props.count)
}
})
const root = nodeOps.createElement('div')
render(h(Parent), root)
expect(serializeInner(root)).toMatch(`<div>0</div>`)
expect(dummy).toBe(0)
// props should be reactive
count.value++
await nextTick()
expect(serializeInner(root)).toMatch(`<div>1</div>`)
expect(dummy).toBe(1)
})
it('context.attrs', async () => {
const toggle = ref(true)