@@ -36,9 +36,9 @@ describe('hot module replacement', () => {
36
36
} )
37
37
38
38
test ( 'createRecord' , ( ) => {
39
- expect ( createRecord ( 'test1' ) ) . toBe ( true )
39
+ expect ( createRecord ( 'test1' , { } ) ) . toBe ( true )
40
40
// if id has already been created, should return false
41
- expect ( createRecord ( 'test1' ) ) . toBe ( false )
41
+ expect ( createRecord ( 'test1' , { } ) ) . toBe ( false )
42
42
} )
43
43
44
44
test ( 'rerender' , async ( ) => {
@@ -50,7 +50,7 @@ describe('hot module replacement', () => {
50
50
__hmrId : childId ,
51
51
render : compileToFunction ( `<div><slot/></div>` )
52
52
}
53
- createRecord ( childId )
53
+ createRecord ( childId , Child )
54
54
55
55
const Parent : ComponentOptions = {
56
56
__hmrId : parentId ,
@@ -62,7 +62,7 @@ describe('hot module replacement', () => {
62
62
`<div @click="count++">{{ count }}<Child>{{ count }}</Child></div>`
63
63
)
64
64
}
65
- createRecord ( parentId )
65
+ createRecord ( parentId , Parent )
66
66
67
67
render ( h ( Parent ) , root )
68
68
expect ( serializeInner ( root ) ) . toBe ( `<div>0<div>0</div></div>` )
@@ -128,7 +128,7 @@ describe('hot module replacement', () => {
128
128
unmounted : unmountSpy ,
129
129
render : compileToFunction ( `<div @click="count++">{{ count }}</div>` )
130
130
}
131
- createRecord ( childId )
131
+ createRecord ( childId , Child )
132
132
133
133
const Parent : ComponentOptions = {
134
134
render : ( ) => h ( Child )
@@ -167,7 +167,7 @@ describe('hot module replacement', () => {
167
167
render : compileToFunction ( `<div @click="count++">{{ count }}</div>` )
168
168
}
169
169
}
170
- createRecord ( childId )
170
+ createRecord ( childId , Child )
171
171
172
172
const Parent : ComponentOptions = {
173
173
render : ( ) => h ( Child )
@@ -212,7 +212,7 @@ describe('hot module replacement', () => {
212
212
} ,
213
213
render : compileToFunction ( template )
214
214
}
215
- createRecord ( id )
215
+ createRecord ( id , Comp )
216
216
217
217
render ( h ( Comp ) , root )
218
218
expect ( serializeInner ( root ) ) . toBe (
@@ -249,14 +249,14 @@ describe('hot module replacement', () => {
249
249
} ,
250
250
render : compileToFunction ( `<div>{{ msg }}</div>` )
251
251
}
252
- createRecord ( childId )
252
+ createRecord ( childId , Child )
253
253
254
254
const Parent : ComponentOptions = {
255
255
__hmrId : parentId ,
256
256
components : { Child } ,
257
257
render : compileToFunction ( `<Child msg="foo" />` )
258
258
}
259
- createRecord ( parentId )
259
+ createRecord ( parentId , Parent )
260
260
261
261
render ( h ( Parent ) , root )
262
262
expect ( serializeInner ( root ) ) . toBe ( `<div>foo</div>` )
@@ -275,14 +275,14 @@ describe('hot module replacement', () => {
275
275
__hmrId : childId ,
276
276
render : compileToFunction ( `<div>child</div>` )
277
277
}
278
- createRecord ( childId )
278
+ createRecord ( childId , Child )
279
279
280
280
const Parent : ComponentOptions = {
281
281
__hmrId : parentId ,
282
282
components : { Child } ,
283
283
render : compileToFunction ( `<Child class="test" />` )
284
284
}
285
- createRecord ( parentId )
285
+ createRecord ( parentId , Parent )
286
286
287
287
render ( h ( Parent ) , root )
288
288
expect ( serializeInner ( root ) ) . toBe ( `<div class="test">child</div>` )
@@ -302,7 +302,7 @@ describe('hot module replacement', () => {
302
302
__hmrId : childId ,
303
303
render : compileToFunction ( `<div>child</div>` )
304
304
}
305
- createRecord ( childId )
305
+ createRecord ( childId , Child )
306
306
307
307
const components : ComponentOptions [ ] = [ ]
308
308
@@ -324,7 +324,7 @@ describe('hot module replacement', () => {
324
324
}
325
325
}
326
326
327
- createRecord ( parentId )
327
+ createRecord ( parentId , parentComp )
328
328
}
329
329
330
330
const last = components [ components . length - 1 ]
@@ -370,7 +370,7 @@ describe('hot module replacement', () => {
370
370
</Child>
371
371
` )
372
372
}
373
- createRecord ( parentId )
373
+ createRecord ( parentId , Parent )
374
374
375
375
render ( h ( Parent ) , root )
376
376
expect ( serializeInner ( root ) ) . toBe (
@@ -410,7 +410,7 @@ describe('hot module replacement', () => {
410
410
return h ( 'div' )
411
411
}
412
412
}
413
- createRecord ( childId )
413
+ createRecord ( childId , Child )
414
414
415
415
const Parent : ComponentOptions = {
416
416
render : ( ) => h ( Child )
@@ -435,4 +435,38 @@ describe('hot module replacement', () => {
435
435
expect ( createSpy1 ) . toHaveBeenCalledTimes ( 1 )
436
436
expect ( createSpy2 ) . toHaveBeenCalledTimes ( 1 )
437
437
} )
438
+
439
+ // #4757
440
+ test ( 'rerender for component that has no active instance yet' , ( ) => {
441
+ const id = 'no-active-instance-rerender'
442
+ const Foo : ComponentOptions = {
443
+ __hmrId : id ,
444
+ render : ( ) => 'foo'
445
+ }
446
+
447
+ createRecord ( id , Foo )
448
+ rerender ( id , ( ) => 'bar' )
449
+
450
+ const root = nodeOps . createElement ( 'div' )
451
+ render ( h ( Foo ) , root )
452
+ expect ( serializeInner ( root ) ) . toBe ( 'bar' )
453
+ } )
454
+
455
+ test ( 'reload for component that has no active instance yet' , ( ) => {
456
+ const id = 'no-active-instance-reload'
457
+ const Foo : ComponentOptions = {
458
+ __hmrId : id ,
459
+ render : ( ) => 'foo'
460
+ }
461
+
462
+ createRecord ( id , Foo )
463
+ reload ( id , {
464
+ __hmrId : id ,
465
+ render : ( ) => 'bar'
466
+ } )
467
+
468
+ const root = nodeOps . createElement ( 'div' )
469
+ render ( h ( Foo ) , root )
470
+ expect ( serializeInner ( root ) ) . toBe ( 'bar' )
471
+ } )
438
472
} )
0 commit comments