test(runtime-core): add test for rendererComponent (#1393)

This commit is contained in:
春去春又来 2020-07-15 21:34:23 +08:00 committed by GitHub
parent b772bba558
commit 379a8af288
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,4 +40,45 @@ describe('renderer: component', () => {
expect(serializeInner(root)).toBe(`<span></span>`)
expect(parentVnode!.el).toBe(childVnode2!.el)
})
it('should create an Component with props', () => {
const Comp = {
render: () => {
return h('div')
}
}
const root = nodeOps.createElement('div')
render(h(Comp, { id: 'foo', class: 'bar' }), root)
expect(serializeInner(root)).toBe(`<div id="foo" class="bar"></div>`)
})
it('should create an Component with direct text children', () => {
const Comp = {
render: () => {
return h('div', 'test')
}
}
const root = nodeOps.createElement('div')
render(h(Comp, { id: 'foo', class: 'bar' }), root)
expect(serializeInner(root)).toBe(`<div id="foo" class="bar">test</div>`)
})
it('should update an Component tag which is already mounted', () => {
const Comp1 = {
render: () => {
return h('div', 'foo')
}
}
const root = nodeOps.createElement('div')
render(h(Comp1), root)
expect(serializeInner(root)).toBe('<div>foo</div>')
const Comp2 = {
render: () => {
return h('span', 'foo')
}
}
render(h(Comp2), root)
expect(serializeInner(root)).toBe('<span>foo</span>')
})
})