Skip to content

test: test for runtime/h #746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions test/v3/runtime-core/h.spec.ts
Original file line number Diff line number Diff line change
@@ -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>`)
})
})