Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>`) | ||
}) | ||
}) |