@@ -11,12 +11,13 @@ import {
11
11
nextTick
12
12
} from '@vue/runtime-test'
13
13
import * as runtimeTest from '@vue/runtime-test'
14
+ import { registerRuntimeCompiler , createApp } from '@vue/runtime-test'
14
15
import { baseCompile } from '@vue/compiler-core'
15
16
16
17
declare var __VUE_HMR_RUNTIME__ : HMRRuntime
17
18
const { createRecord, rerender, reload } = __VUE_HMR_RUNTIME__
18
19
19
- runtimeTest . registerRuntimeCompiler ( compileToFunction )
20
+ registerRuntimeCompiler ( compileToFunction )
20
21
21
22
function compileToFunction ( template : string ) {
22
23
const { code } = baseCompile ( template )
@@ -395,4 +396,43 @@ describe('hot module replacement', () => {
395
396
`<div style={}><div>1</div><div>2</div></div>`
396
397
)
397
398
} )
399
+
400
+ // #4174
401
+ test ( 'with global mixins' , async ( ) => {
402
+ const childId = 'hmr-global-mixin'
403
+ const createSpy1 = jest . fn ( )
404
+ const createSpy2 = jest . fn ( )
405
+
406
+ const Child : ComponentOptions = {
407
+ __hmrId : childId ,
408
+ created : createSpy1 ,
409
+ render ( ) {
410
+ return h ( 'div' )
411
+ }
412
+ }
413
+ createRecord ( childId , Child )
414
+
415
+ const Parent : ComponentOptions = {
416
+ render : ( ) => h ( Child )
417
+ }
418
+
419
+ const app = createApp ( Parent )
420
+ app . mixin ( { } )
421
+
422
+ const root = nodeOps . createElement ( 'div' )
423
+ app . mount ( root )
424
+ expect ( createSpy1 ) . toHaveBeenCalledTimes ( 1 )
425
+ expect ( createSpy2 ) . toHaveBeenCalledTimes ( 0 )
426
+
427
+ reload ( childId , {
428
+ __hmrId : childId ,
429
+ created : createSpy2 ,
430
+ render ( ) {
431
+ return h ( 'div' )
432
+ }
433
+ } )
434
+ await nextTick ( )
435
+ expect ( createSpy1 ) . toHaveBeenCalledTimes ( 1 )
436
+ expect ( createSpy2 ) . toHaveBeenCalledTimes ( 1 )
437
+ } )
398
438
} )
0 commit comments