@@ -159,132 +159,150 @@ describe('Instance Events', function () {
159
159
expect ( spy ) . toHaveBeenCalled ( )
160
160
} )
161
161
162
- if ( Vue . util . inBrowser ) {
162
+ it ( 'beforeCompile' , function ( ) {
163
+ var vm = new Vue ( {
164
+ template : '{{a}}' ,
165
+ data : { a : 1 } ,
166
+ beforeCompile : function ( ) {
167
+ expect ( this ) . toBe ( vm )
168
+ expect ( this . $el ) . toBe ( el )
169
+ expect ( this . $el . textContent ) . toBe ( '{{a}}' )
170
+ spy ( )
171
+ }
172
+ } )
173
+ var el = document . createElement ( 'div' )
174
+ vm . $mount ( el )
175
+ expect ( spy ) . toHaveBeenCalled ( )
176
+ } )
163
177
164
- it ( 'beforeCompile' , function ( ) {
165
- var vm = new Vue ( {
166
- template : '{{a}}' ,
167
- data : { a : 1 } ,
168
- beforeCompile : function ( ) {
169
- expect ( this ) . toBe ( vm )
170
- expect ( this . $el ) . toBe ( el )
171
- expect ( this . $el . textContent ) . toBe ( '{{a}}' )
172
- spy ( )
173
- }
174
- } )
175
- var el = document . createElement ( 'div' )
176
- vm . $mount ( el )
177
- expect ( spy ) . toHaveBeenCalled ( )
178
+ it ( 'compiled' , function ( ) {
179
+ var vm = new Vue ( {
180
+ template : '{{a}}' ,
181
+ data : { a : 1 } ,
182
+ compiled : function ( ) {
183
+ expect ( this . $el ) . toBe ( el )
184
+ expect ( this . $el . textContent ) . toBe ( '1' )
185
+ spy ( )
186
+ }
187
+ } )
188
+ var el = document . createElement ( 'div' )
189
+ vm . $mount ( el )
190
+ expect ( spy ) . toHaveBeenCalled ( )
191
+ } )
192
+
193
+ it ( 'ready' , function ( ) {
194
+ var vm = new Vue ( {
195
+ ready : spy
178
196
} )
197
+ expect ( spy ) . not . toHaveBeenCalled ( )
198
+ var el = document . createElement ( 'div' )
199
+ vm . $mount ( el )
200
+ expect ( spy ) . not . toHaveBeenCalled ( )
201
+ vm . $appendTo ( document . body )
202
+ expect ( spy ) . toHaveBeenCalled ( )
203
+ vm . $remove ( )
204
+ // try mounting on something already in dom
205
+ el = document . createElement ( 'div' )
206
+ document . body . appendChild ( el )
207
+ vm = new Vue ( {
208
+ el : el ,
209
+ ready : spy2
210
+ } )
211
+ expect ( spy2 ) . toHaveBeenCalled ( )
212
+ vm . $remove ( )
213
+ } )
179
214
180
- it ( 'compiled' , function ( ) {
181
- var vm = new Vue ( {
182
- template : '{{a}}' ,
183
- data : { a : 1 } ,
184
- compiled : function ( ) {
185
- expect ( this . $el ) . toBe ( el )
186
- expect ( this . $el . textContent ) . toBe ( '1' )
187
- spy ( )
215
+ it ( 'compile v-on on child component' , function ( ) {
216
+ var vm = new Vue ( {
217
+ el : document . createElement ( 'div' ) ,
218
+ template : '<comp v-on:hook:created="onCreated" @ready="onReady" @ok="a++"></comp>' ,
219
+ data : {
220
+ a : 0
221
+ } ,
222
+ methods : {
223
+ onCreated : spy ,
224
+ onReady : spy
225
+ } ,
226
+ components : {
227
+ comp : {
228
+ compiled : function ( ) {
229
+ this . $emit ( 'ready' , 123 )
230
+ this . $emit ( 'ok' )
231
+ }
188
232
}
189
- } )
190
- var el = document . createElement ( 'div' )
191
- vm . $mount ( el )
192
- expect ( spy ) . toHaveBeenCalled ( )
233
+ }
193
234
} )
235
+ expect ( spy . calls . count ( ) ) . toBe ( 2 )
236
+ expect ( spy ) . toHaveBeenCalledWith ( 123 )
237
+ expect ( vm . a ) . toBe ( 1 )
238
+ } )
194
239
195
- it ( 'ready' , function ( ) {
196
- var vm = new Vue ( {
197
- ready : spy
198
- } )
199
- expect ( spy ) . not . toHaveBeenCalled ( )
240
+ describe ( 'attached/detached' , function ( ) {
241
+
242
+ it ( 'in DOM' , function ( ) {
200
243
var el = document . createElement ( 'div' )
201
- vm . $mount ( el )
202
- expect ( spy ) . not . toHaveBeenCalled ( )
203
- vm . $appendTo ( document . body )
204
- expect ( spy ) . toHaveBeenCalled ( )
205
- vm . $remove ( )
206
- // try mounting on something already in dom
207
- el = document . createElement ( 'div' )
244
+ var childEl = document . createElement ( 'div' )
245
+ el . appendChild ( childEl )
208
246
document . body . appendChild ( el )
209
- vm = new Vue ( {
247
+ var parentVm = new Vue ( {
210
248
el : el ,
211
- ready : spy2
249
+ attached : spy ,
250
+ detached : spy2
212
251
} )
213
- expect ( spy2 ) . toHaveBeenCalled ( )
214
- vm . $remove ( )
252
+ var childVm = parentVm . $addChild ( {
253
+ el : childEl ,
254
+ attached : spy ,
255
+ detached : spy2
256
+ } )
257
+ expect ( spy . calls . count ( ) ) . toBe ( 2 )
258
+ parentVm . $remove ( )
259
+ expect ( spy2 . calls . count ( ) ) . toBe ( 2 )
260
+ // child should be already detached
261
+ // so the hook should not fire again
262
+ childVm . $remove ( )
263
+ expect ( spy2 . calls . count ( ) ) . toBe ( 2 )
215
264
} )
216
265
217
- describe ( 'attached/detached' , function ( ) {
218
-
219
- it ( 'in DOM' , function ( ) {
220
- var el = document . createElement ( 'div' )
221
- var childEl = document . createElement ( 'div' )
222
- el . appendChild ( childEl )
223
- document . body . appendChild ( el )
224
- var parentVm = new Vue ( {
225
- el : el ,
226
- attached : spy ,
227
- detached : spy2
228
- } )
229
- var childVm = parentVm . $addChild ( {
230
- el : childEl ,
231
- attached : spy ,
232
- detached : spy2
233
- } )
234
- expect ( spy . calls . count ( ) ) . toBe ( 2 )
235
- parentVm . $remove ( )
236
- expect ( spy2 . calls . count ( ) ) . toBe ( 2 )
237
- // child should be already detached
238
- // so the hook should not fire again
239
- childVm . $remove ( )
240
- expect ( spy2 . calls . count ( ) ) . toBe ( 2 )
266
+ it ( 'create then attach' , function ( ) {
267
+ var el = document . createElement ( 'div' )
268
+ var childEl = document . createElement ( 'div' )
269
+ el . appendChild ( childEl )
270
+ var parentVm = new Vue ( {
271
+ el : el ,
272
+ attached : spy ,
273
+ detached : spy2
241
274
} )
242
-
243
- it ( 'create then attach' , function ( ) {
244
- var el = document . createElement ( 'div' )
245
- var childEl = document . createElement ( 'div' )
246
- el . appendChild ( childEl )
247
- var parentVm = new Vue ( {
248
- el : el ,
249
- attached : spy ,
250
- detached : spy2
251
- } )
252
- var childVm = parentVm . $addChild ( {
253
- el : childEl ,
254
- attached : spy ,
255
- detached : spy2
256
- } )
257
- parentVm . $appendTo ( document . body )
258
- expect ( spy . calls . count ( ) ) . toBe ( 2 )
259
- // detach child first
260
- childVm . $remove ( )
261
- expect ( spy2 . calls . count ( ) ) . toBe ( 1 )
262
- // should only fire parent detach
263
- parentVm . $remove ( )
264
- expect ( spy2 . calls . count ( ) ) . toBe ( 2 )
275
+ var childVm = parentVm . $addChild ( {
276
+ el : childEl ,
277
+ attached : spy ,
278
+ detached : spy2
265
279
} )
280
+ parentVm . $appendTo ( document . body )
281
+ expect ( spy . calls . count ( ) ) . toBe ( 2 )
282
+ // detach child first
283
+ childVm . $remove ( )
284
+ expect ( spy2 . calls . count ( ) ) . toBe ( 1 )
285
+ // should only fire parent detach
286
+ parentVm . $remove ( )
287
+ expect ( spy2 . calls . count ( ) ) . toBe ( 2 )
288
+ } )
266
289
267
- it ( 'should not fire on detached child' , function ( ) {
268
- var el = document . createElement ( 'div' )
269
- var childEl = document . createElement ( 'div' )
270
- var parentVm = new Vue ( {
271
- el : el ,
272
- attached : spy
273
- } )
274
- var childVm = parentVm . $addChild ( {
275
- el : childEl ,
276
- attached : spy
277
- } )
278
- parentVm . $appendTo ( document . body )
279
- expect ( spy . calls . count ( ) ) . toBe ( 1 )
280
- childVm . $appendTo ( el )
281
- expect ( spy . calls . count ( ) ) . toBe ( 2 )
290
+ it ( 'should not fire on detached child' , function ( ) {
291
+ var el = document . createElement ( 'div' )
292
+ var childEl = document . createElement ( 'div' )
293
+ var parentVm = new Vue ( {
294
+ el : el ,
295
+ attached : spy
282
296
} )
283
-
297
+ var childVm = parentVm . $addChild ( {
298
+ el : childEl ,
299
+ attached : spy
300
+ } )
301
+ parentVm . $appendTo ( document . body )
302
+ expect ( spy . calls . count ( ) ) . toBe ( 1 )
303
+ childVm . $appendTo ( el )
304
+ expect ( spy . calls . count ( ) ) . toBe ( 2 )
284
305
} )
285
-
286
- }
287
-
306
+ } )
288
307
} )
289
-
290
308
} )
0 commit comments