1- import { h , createApp } from '../../../src'
2- import { mockWarn } from '../../helpers'
1+ import { h , createApp , ref , getCurrentInstance } from '../../../src'
2+ import { mockWarn , sleep } from '../../helpers'
33
44describe ( 'renderer: h' , ( ) => {
55 mockWarn ( true )
@@ -10,6 +10,45 @@ describe('renderer: h', () => {
1010 ) . toHaveBeenWarned ( )
1111 } )
1212
13+ it ( 'should not warn with called outside of render function' , async ( ) => {
14+ const spy = jest . fn ( )
15+ const Comp = {
16+ setup ( ) {
17+ const instance = getCurrentInstance ( )
18+ const createElement = h . bind ( instance )
19+ const renderVnode = ( ) => createElement ( 'p' , { } )
20+ setTimeout ( renderVnode , 10 )
21+ } ,
22+ }
23+ const root = document . createElement ( 'div' )
24+ createApp ( Comp ) . mount ( root )
25+ await sleep ( 50 )
26+
27+ expect ( spy ) . toHaveBeenCalledTimes ( 0 )
28+ } )
29+
30+ it ( `Should support h's responsive rendering` , async ( ) => {
31+ const Comp = {
32+ setup ( ) {
33+ const showNode1 = ref ( true )
34+ setTimeout ( ( ) => {
35+ showNode1 . value = false
36+ } , 10 )
37+ return ( ) =>
38+ showNode1 . value
39+ ? h ( 'div' , void 0 , [ h ( 'br' ) , 'hello world' , h ( 'br' ) ] )
40+ : h ( 'div' , void 0 , [ h ( 'div' ) , 'nextTick render' , h ( 'div' ) ] )
41+ } ,
42+ }
43+ const root = document . createElement ( 'div' )
44+ const vm = createApp ( Comp ) . mount ( root )
45+ expect ( vm . $el . outerHTML ) . toBe ( `<div><br>hello world<br></div>` )
46+ await sleep ( 50 )
47+ expect ( vm . $el . outerHTML ) . toBe (
48+ `<div><div></div>nextTick render<div></div></div>`
49+ )
50+ } )
51+
1352 it ( 'should work with called outside of render function' , ( ) => {
1453 const msg = 'hello world'
1554 const vnode = h ( 'hello-world' , {
0 commit comments