Skip to content

Commit 379a8af

Browse files
authored
test(runtime-core): add test for rendererComponent (vuejs#1393)
1 parent b772bba commit 379a8af

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

packages/runtime-core/__tests__/rendererComponent.spec.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,45 @@ describe('renderer: component', () => {
4040
expect(serializeInner(root)).toBe(`<span></span>`)
4141
expect(parentVnode!.el).toBe(childVnode2!.el)
4242
})
43+
44+
it('should create an Component with props', () => {
45+
const Comp = {
46+
render: () => {
47+
return h('div')
48+
}
49+
}
50+
const root = nodeOps.createElement('div')
51+
render(h(Comp, { id: 'foo', class: 'bar' }), root)
52+
expect(serializeInner(root)).toBe(`<div id="foo" class="bar"></div>`)
53+
})
54+
55+
it('should create an Component with direct text children', () => {
56+
const Comp = {
57+
render: () => {
58+
return h('div', 'test')
59+
}
60+
}
61+
const root = nodeOps.createElement('div')
62+
render(h(Comp, { id: 'foo', class: 'bar' }), root)
63+
expect(serializeInner(root)).toBe(`<div id="foo" class="bar">test</div>`)
64+
})
65+
66+
it('should update an Component tag which is already mounted', () => {
67+
const Comp1 = {
68+
render: () => {
69+
return h('div', 'foo')
70+
}
71+
}
72+
const root = nodeOps.createElement('div')
73+
render(h(Comp1), root)
74+
expect(serializeInner(root)).toBe('<div>foo</div>')
75+
76+
const Comp2 = {
77+
render: () => {
78+
return h('span', 'foo')
79+
}
80+
}
81+
render(h(Comp2), root)
82+
expect(serializeInner(root)).toBe('<span>foo</span>')
83+
})
4384
})

0 commit comments

Comments
 (0)