File tree Expand file tree Collapse file tree 2 files changed +56
-2
lines changed Expand file tree Collapse file tree 2 files changed +56
-2
lines changed Original file line number Diff line number Diff line change @@ -386,8 +386,12 @@ export function mount(
386
386
}
387
387
388
388
if ( global . components ) {
389
- for ( const key of Object . keys ( global . components ) )
390
- app . component ( key , global . components [ key ] )
389
+ for ( const key of Object . keys ( global . components ) ) {
390
+ // avoid registering components that are stubbed twice
391
+ if ( ! global . stubs [ key ] ) {
392
+ app . component ( key , global . components [ key ] )
393
+ }
394
+ }
391
395
}
392
396
393
397
if ( global . directives ) {
Original file line number Diff line number Diff line change @@ -18,4 +18,54 @@ describe('global.components', () => {
18
18
19
19
expect ( wrapper . text ( ) ) . toBe ( 'Global' )
20
20
} )
21
+
22
+ it ( 'allows global stubs to take precedence without warning' , ( ) => {
23
+ const GlobalComponent = {
24
+ template : '<div>Global</div>'
25
+ }
26
+ const spy = jest . spyOn ( console , 'warn' )
27
+ const wrapper = mount (
28
+ {
29
+ template : '<div><global-component/></div>'
30
+ } ,
31
+ {
32
+ global : {
33
+ components : {
34
+ GlobalComponent
35
+ } ,
36
+ stubs : { GlobalComponent : true }
37
+ }
38
+ }
39
+ )
40
+
41
+ expect ( spy ) . not . toHaveBeenCalled ( )
42
+ spy . mockRestore ( )
43
+ expect ( wrapper . html ( ) ) . toBe (
44
+ `<div><global-component-stub></global-component-stub></div>`
45
+ )
46
+ } )
47
+
48
+ it ( 'allows global stubs to be deactivated without warning' , ( ) => {
49
+ const GlobalComponent = {
50
+ template : '<div>Global</div>'
51
+ }
52
+ const spy = jest . spyOn ( console , 'warn' )
53
+ const wrapper = mount (
54
+ {
55
+ template : '<div><global-component/></div>'
56
+ } ,
57
+ {
58
+ global : {
59
+ components : {
60
+ GlobalComponent
61
+ } ,
62
+ stubs : { GlobalComponent : false }
63
+ }
64
+ }
65
+ )
66
+
67
+ expect ( spy ) . not . toHaveBeenCalled ( )
68
+ spy . mockRestore ( )
69
+ expect ( wrapper . text ( ) ) . toBe ( 'Global' )
70
+ } )
21
71
} )
You can’t perform that action at this time.
0 commit comments