Skip to content

Commit bc4e0ea

Browse files
authored
test: test for runtime/h (#746)
Co-authored-by: webfansplz <>
1 parent c4dfc10 commit bc4e0ea

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/v3/runtime-core/h.spec.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { h, createApp } from '../../../src'
2+
import { mockWarn } from '../../helpers'
3+
4+
describe('renderer: h', () => {
5+
mockWarn(true)
6+
it('should warn with called outside of render function', () => {
7+
h('p', {})
8+
expect(
9+
'[Vue warn]: `createElement()` has been called outside of render function.'
10+
).toHaveBeenWarned()
11+
})
12+
13+
it('should work with called outside of render function', () => {
14+
const msg = 'hello world'
15+
const vnode = h('hello-world', {
16+
props: {
17+
msg,
18+
},
19+
})
20+
expect(
21+
'[Vue warn]: `createElement()` has been called outside of render function.'
22+
).toHaveBeenWarned()
23+
expect(vnode.tag).toEqual('hello-world')
24+
expect(vnode.children).toBeUndefined()
25+
expect(vnode.text).toBeUndefined()
26+
expect(vnode.elm).toBeUndefined()
27+
expect(vnode.ns).toBeUndefined()
28+
expect(vnode.data?.props).toEqual({ msg })
29+
})
30+
31+
it('render vnode with createElement with children', () => {
32+
const Comp = {
33+
setup() {
34+
return () => h('div', void 0, [h('br'), 'hello world', h('br')])
35+
},
36+
}
37+
const root = document.createElement('div')
38+
const vm = createApp(Comp).mount(root)
39+
expect(vm.$el.outerHTML).toBe(`<div><br>hello world<br></div>`)
40+
})
41+
})

0 commit comments

Comments
 (0)