@@ -61,41 +61,50 @@ function createBlankStub (originalComponent: Component) {
61
61
}
62
62
63
63
export function stubComponents ( component : Component , stubs : Object ) : void {
64
- Object . keys ( stubs ) . forEach ( stub => {
65
- if ( ! isValidStub ( stubs [ stub ] ) ) {
66
- throwError ( 'options.stub values must be passed a string or component' )
67
- }
68
-
69
- if ( ! component . components ) {
70
- component . components = { }
71
- }
64
+ if ( ! component . components ) {
65
+ component . components = { }
66
+ }
72
67
73
- if ( component . components [ stub ] ) {
74
- // Remove cached constructor
75
- delete component . components [ stub ] . _Ctor
76
- if ( typeof stubs [ stub ] === ' string') {
77
- component . components [ stub ] = createStubFromString ( stubs [ stub ] , component . components [ stub ] )
78
- stubLifeCycleEvents ( component . components [ stub ] )
79
- } else {
80
- component . components [ stub ] = {
81
- ... stubs [ stub ] ,
82
- name : component . components [ stub ] . name
83
- }
68
+ if ( Array . isArray ( stubs ) ) {
69
+ stubs . forEach ( stub => {
70
+ if ( typeof stub !== 'string' ) {
71
+ throwError ( 'each item in options. stub must be a string')
72
+ }
73
+ component . components [ stub ] = createBlankStub ( { } )
74
+ } )
75
+ } else {
76
+ Object . keys ( stubs ) . forEach ( stub => {
77
+ if ( ! isValidStub ( stubs [ stub ] ) ) {
78
+ throwError ( 'options.stub values must be passed a string or component' )
84
79
}
85
- } else {
86
- if ( typeof stubs [ stub ] === 'string' ) {
87
- component . components [ stub ] = {
88
- ...compileToFunctions ( stubs [ stub ] )
80
+
81
+ if ( component . components [ stub ] ) {
82
+ // Remove cached constructor
83
+ delete component . components [ stub ] . _Ctor
84
+ if ( typeof stubs [ stub ] === 'string' ) {
85
+ component . components [ stub ] = createStubFromString ( stubs [ stub ] , component . components [ stub ] )
86
+ stubLifeCycleEvents ( component . components [ stub ] )
87
+ } else {
88
+ component . components [ stub ] = {
89
+ ...stubs [ stub ] ,
90
+ name : component . components [ stub ] . name
91
+ }
89
92
}
90
- stubLifeCycleEvents ( component . components [ stub ] )
91
93
} else {
92
- component . components [ stub ] = {
93
- ...stubs [ stub ]
94
+ if ( typeof stubs [ stub ] === 'string' ) {
95
+ component . components [ stub ] = {
96
+ ...compileToFunctions ( stubs [ stub ] )
97
+ }
98
+ stubLifeCycleEvents ( component . components [ stub ] )
99
+ } else {
100
+ component . components [ stub ] = {
101
+ ...stubs [ stub ]
102
+ }
94
103
}
95
104
}
96
- }
97
- Vue . config . ignoredElements . push ( stub )
98
- } )
105
+ Vue . config . ignoredElements . push ( stub )
106
+ } )
107
+ }
99
108
}
100
109
101
110
export function stubAllComponents ( component : Component ) : void {
0 commit comments