File tree Expand file tree Collapse file tree 4 files changed +115
-2
lines changed Expand file tree Collapse file tree 4 files changed +115
-2
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ exports.test = function (configs, cb) {
24
24
var config = configs [ route ]
25
25
Object . keys ( config ) . forEach ( function ( hook ) {
26
26
var fn = config [ hook ]
27
+ if ( Array . isArray ( fn ) || hook === 'mixins' ) {
28
+ return
29
+ }
27
30
if ( fn . length ) {
28
31
config [ hook ] = function ( transition ) {
29
32
var event = route + '.' + hook
@@ -84,12 +87,15 @@ exports.test = function (configs, cb) {
84
87
'/data/:msg' : {
85
88
component : {
86
89
route : configs . data ,
90
+ mixins : configs . data && configs . data . mixins ,
87
91
template :
88
92
'<span v-if="$loadingRouteData">loading...</span>' +
89
- '<span v-if="!$loadingRouteData">{{msg}}</span>' ,
93
+ '<span v-if="!$loadingRouteData">{{msg}}{{otherMsg}}{{thirdMsg}} </span>' ,
90
94
data : function ( ) {
91
95
return {
92
- msg : 'default'
96
+ msg : 'default' ,
97
+ otherMsg : '' ,
98
+ thirdMsg : ''
93
99
}
94
100
}
95
101
}
Original file line number Diff line number Diff line change @@ -168,4 +168,34 @@ describe('activate', function () {
168
168
done ( )
169
169
} )
170
170
} )
171
+
172
+ it ( 'multiple' , function ( done ) {
173
+ var calls = [ ]
174
+ test ( {
175
+ a : {
176
+ activate : [
177
+ function ( transition ) {
178
+ calls . push ( 1 )
179
+ setTimeout ( function ( ) {
180
+ transition . next ( )
181
+ } , wait )
182
+ } ,
183
+ function ( ) {
184
+ calls . push ( 2 )
185
+ return new Promise ( function ( resolve ) {
186
+ setTimeout ( resolve , wait )
187
+ } )
188
+ }
189
+ ]
190
+ }
191
+ } , function ( router , _ , emitter ) {
192
+ router . go ( '/a' )
193
+ expect ( router . app . $el . textContent ) . toBe ( '' )
194
+ setTimeout ( function ( ) {
195
+ assertCalls ( calls , [ 1 , 2 ] )
196
+ expect ( router . app . $el . textContent ) . toBe ( 'A ' )
197
+ done ( )
198
+ } , wait * 3 )
199
+ } )
200
+ } )
171
201
} )
Original file line number Diff line number Diff line change @@ -196,4 +196,49 @@ describe('data', function () {
196
196
} , wait * 2 )
197
197
} )
198
198
} )
199
+
200
+ it ( 'multiple data hooks' , function ( done ) {
201
+ test ( {
202
+ data : {
203
+ data : [
204
+ function ( transition ) {
205
+ return {
206
+ msg : new Promise ( function ( resolve ) {
207
+ setTimeout ( function ( ) {
208
+ resolve ( transition . to . params . msg )
209
+ } , wait )
210
+ } )
211
+ }
212
+ } ,
213
+ function ( transition ) {
214
+ return new Promise ( function ( resolve ) {
215
+ setTimeout ( function ( ) {
216
+ resolve ( {
217
+ otherMsg : ' ' + transition . to . params . msg + '2'
218
+ } )
219
+ } , wait )
220
+ } )
221
+ }
222
+ ] ,
223
+ mixins : [
224
+ {
225
+ route : {
226
+ data : function ( transition ) {
227
+ transition . next ( {
228
+ thirdMsg : ' ' + transition . to . params . msg + '3'
229
+ } )
230
+ }
231
+ }
232
+ }
233
+ ]
234
+ }
235
+ } , function ( router , calls , emitter ) {
236
+ router . go ( '/data/hello' )
237
+ expect ( router . app . $el . textContent ) . toBe ( 'loading...' )
238
+ setTimeout ( function ( ) {
239
+ expect ( router . app . $el . textContent ) . toBe ( 'hello hello2 hello3' )
240
+ done ( )
241
+ } , wait * 3 )
242
+ } )
243
+ } )
199
244
} )
Original file line number Diff line number Diff line change @@ -154,4 +154,36 @@ describe('deactivate', function () {
154
154
} , wait * 2 )
155
155
} )
156
156
} )
157
+
158
+ it ( 'multiple' , function ( done ) {
159
+ var calls = [ ]
160
+ test ( {
161
+ a : {
162
+ deactivate : [
163
+ function ( transition ) {
164
+ calls . push ( 1 )
165
+ setTimeout ( function ( ) {
166
+ transition . next ( )
167
+ } , wait )
168
+ } ,
169
+ function ( ) {
170
+ calls . push ( 2 )
171
+ return new Promise ( function ( resolve ) {
172
+ setTimeout ( resolve , wait )
173
+ } )
174
+ }
175
+ ]
176
+ }
177
+ } , function ( router , _ , emitter ) {
178
+ router . go ( '/a' )
179
+ expect ( router . app . $el . textContent ) . toBe ( 'A ' )
180
+ router . go ( '/b' )
181
+ expect ( router . app . $el . textContent ) . toBe ( 'A ' )
182
+ setTimeout ( function ( ) {
183
+ assertCalls ( calls , [ 1 , 2 ] )
184
+ expect ( router . app . $el . textContent ) . toBe ( '' )
185
+ done ( )
186
+ } , wait * 3 )
187
+ } )
188
+ } )
157
189
} )
You can’t perform that action at this time.
0 commit comments