@@ -9,6 +9,7 @@ module('call-remote-callbacks', {
9
9
teardown : function ( ) {
10
10
$ ( document ) . undelegate ( 'form[data-remote]' , 'ajax:beforeSend' ) ;
11
11
$ ( document ) . undelegate ( 'form[data-remote]' , 'ajax:before' ) ;
12
+ $ ( document ) . undelegate ( 'form[data-remote]' , 'ajax:send' ) ;
12
13
$ ( document ) . undelegate ( 'form[data-remote]' , 'ajax:complete' ) ;
13
14
$ ( document ) . undelegate ( 'form[data-remote]' , 'ajax:success' ) ;
14
15
$ ( document ) . unbind ( 'ajaxStop' ) ;
@@ -97,6 +98,9 @@ asyncTest('stopping the "ajax:beforeSend" event aborts the request', 1, function
97
98
ok ( true , 'aborting request in ajax:beforeSend' ) ;
98
99
return false ;
99
100
} ) ;
101
+ form . unbind ( 'ajax:send' ) . bind ( 'ajax:send' , function ( ) {
102
+ ok ( false , 'ajax:send should not run' ) ;
103
+ } ) ;
100
104
form . unbind ( 'ajax:complete' ) . bind ( 'ajax:complete' , function ( ) {
101
105
ok ( false , 'ajax:complete should not run' ) ;
102
106
} ) ;
@@ -315,6 +319,9 @@ asyncTest('"ajax:beforeSend" can be observed and stopped with event delegation',
315
319
} ) ;
316
320
317
321
submit ( function ( form ) {
322
+ form . unbind ( 'ajax:send' ) . bind ( 'ajax:send' , function ( ) {
323
+ ok ( false , 'ajax:send should not run' ) ;
324
+ } ) ;
318
325
form . unbind ( 'ajax:complete' ) . bind ( 'ajax:complete' , function ( ) {
319
326
ok ( false , 'ajax:complete should not run' ) ;
320
327
} ) ;
@@ -324,12 +331,15 @@ asyncTest('"ajax:beforeSend" can be observed and stopped with event delegation',
324
331
} ) ;
325
332
} ) ;
326
333
327
- asyncTest ( '"ajax:beforeSend", "ajax:success" and "ajax:complete" are triggered' , 8 , function ( ) {
334
+ asyncTest ( '"ajax:beforeSend", "ajax:send", "ajax: success" and "ajax:complete" are triggered' , 9 , function ( ) {
328
335
submit ( function ( form ) {
329
336
form . bind ( 'ajax:beforeSend' , function ( e , xhr , settings ) {
330
337
ok ( xhr . setRequestHeader , 'first argument to "ajax:beforeSend" should be an XHR object' ) ;
331
338
equal ( settings . url , '/echo' , 'second argument to "ajax:beforeSend" should be a settings object' ) ;
332
339
} ) ;
340
+ form . bind ( 'ajax:send' , function ( e , xhr ) {
341
+ ok ( xhr . abort , 'first argument to "ajax:send" should be an XHR object' ) ;
342
+ } ) ;
333
343
form . bind ( 'ajax:success' , function ( e , data , status , xhr ) {
334
344
ok ( data . REQUEST_METHOD , 'first argument to ajax:success should be a data object' ) ;
335
345
equal ( status , 'success' , 'second argument to ajax:success should be a status string' ) ;
@@ -342,10 +352,11 @@ asyncTest('"ajax:beforeSend", "ajax:success" and "ajax:complete" are triggered',
342
352
} ) ;
343
353
} ) ;
344
354
345
- asyncTest ( '"ajax:beforeSend", "ajax:error" and "ajax:complete" are triggered on error' , 6 , function ( ) {
355
+ asyncTest ( '"ajax:beforeSend", "ajax:send", "ajax: error" and "ajax:complete" are triggered on error' , 7 , function ( ) {
346
356
submit ( function ( form ) {
347
357
form . attr ( 'action' , '/error' ) ;
348
358
form . bind ( 'ajax:beforeSend' , function ( arg ) { ok ( true , 'ajax:beforeSend' ) } ) ;
359
+ form . bind ( 'ajax:send' , function ( arg ) { ok ( true , 'ajax:send' ) } ) ;
349
360
form . bind ( 'ajax:error' , function ( e , xhr , status , error ) {
350
361
ok ( xhr . getResponseHeader , 'first argument to "ajax:error" should be an XHR object' ) ;
351
362
equal ( status , 'error' , 'second argument to ajax:error should be a status string' ) ;
@@ -358,11 +369,14 @@ asyncTest('"ajax:beforeSend", "ajax:error" and "ajax:complete" are triggered on
358
369
} ) ;
359
370
360
371
// IF THIS TEST IS FAILING, TRY INCREASING THE TIMEOUT AT THE BOTTOM TO > 100
361
- asyncTest ( 'binding to ajax callbacks via .delegate() triggers handlers properly' , 3 , function ( ) {
372
+ asyncTest ( 'binding to ajax callbacks via .delegate() triggers handlers properly' , 4 , function ( ) {
362
373
$ ( document )
363
374
. delegate ( 'form[data-remote]' , 'ajax:beforeSend' , function ( ) {
364
375
ok ( true , 'ajax:beforeSend handler is triggered' ) ;
365
376
} )
377
+ . delegate ( 'form[data-remote]' , 'ajax:send' , function ( ) {
378
+ ok ( true , 'ajax:send handler is triggered' ) ;
379
+ } )
366
380
. delegate ( 'form[data-remote]' , 'ajax:complete' , function ( ) {
367
381
ok ( true , 'ajax:complete handler is triggered' ) ;
368
382
} )
0 commit comments