Skip to content

Commit

Permalink
test: test for runtime/h (#746)
Browse files Browse the repository at this point in the history
Co-authored-by: webfansplz <>
  • Loading branch information
webfansplz committed Jul 5, 2021
1 parent c4dfc10 commit bc4e0ea
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/v3/runtime-core/h.spec.ts
@@ -0,0 +1,41 @@
import { h, createApp } from '../../../src'
import { mockWarn } from '../../helpers'

describe('renderer: h', () => {
mockWarn(true)
it('should warn with called outside of render function', () => {
h('p', {})
expect(
'[Vue warn]: `createElement()` has been called outside of render function.'
).toHaveBeenWarned()
})

it('should work with called outside of render function', () => {
const msg = 'hello world'
const vnode = h('hello-world', {
props: {
msg,
},
})
expect(
'[Vue warn]: `createElement()` has been called outside of render function.'
).toHaveBeenWarned()
expect(vnode.tag).toEqual('hello-world')
expect(vnode.children).toBeUndefined()
expect(vnode.text).toBeUndefined()
expect(vnode.elm).toBeUndefined()
expect(vnode.ns).toBeUndefined()
expect(vnode.data?.props).toEqual({ msg })
})

it('render vnode with createElement with children', () => {
const Comp = {
setup() {
return () => h('div', void 0, [h('br'), 'hello world', h('br')])
},
}
const root = document.createElement('div')
const vm = createApp(Comp).mount(root)
expect(vm.$el.outerHTML).toBe(`<div><br>hello world<br></div>`)
})
})

0 comments on commit bc4e0ea

Please sign in to comment.