@@ -475,4 +475,61 @@ describe('Commands:', function() {
475
475
. and . calledWith ( 'commandTwo' ) ;
476
476
} ) ;
477
477
} ) ;
478
+
479
+ describe ( 'when registering a command with `complyFor`, then executing it' , function ( ) {
480
+ beforeEach ( function ( ) {
481
+ this . CommandsTwo = _ . clone ( Backbone . Radio . Commands ) ;
482
+ this . callback = stub ( ) ;
483
+ this . Commands . complyFor ( this . CommandsTwo , 'myCommand' , this . callback ) ;
484
+ this . CommandsTwo . command ( 'myCommand' ) ;
485
+ } ) ;
486
+
487
+ it ( 'should execute the callback with the correct context' , function ( ) {
488
+ expect ( this . callback )
489
+ . to . have . been . calledOnce
490
+ . and . to . have . always . been . calledOn ( this . Commands ) ;
491
+ } ) ;
492
+ } ) ;
493
+
494
+ describe ( 'when registering a command with `complyFor` and an event map, and then executing one of the commands' , function ( ) {
495
+ beforeEach ( function ( ) {
496
+ this . CommandsTwo = _ . clone ( Backbone . Radio . Commands ) ;
497
+ this . callbackOne = stub ( ) ;
498
+ this . callbackTwo = stub ( ) ;
499
+ this . Commands . complyFor ( this . CommandsTwo , {
500
+ commandOne : this . callbackOne ,
501
+ commandTwo : this . callbackTwo
502
+ } ) ;
503
+ this . CommandsTwo . command ( 'commandOne' ) ;
504
+ } ) ;
505
+
506
+ it ( 'should execute the callback with the correct context' , function ( ) {
507
+ expect ( this . callbackOne )
508
+ . to . have . been . calledOnce
509
+ . and . to . have . always . been . calledOn ( this . Commands ) ;
510
+ } ) ;
511
+
512
+ it ( 'should not execute the callbacks not specified' , function ( ) {
513
+ expect ( this . callbackTwo ) . to . not . have . been . called ;
514
+ } ) ;
515
+ } ) ;
516
+
517
+ describe ( '`complyForOnce` should clean up after itself' , function ( ) {
518
+ beforeEach ( function ( ) {
519
+ this . CommandsTwo = _ . clone ( Backbone . Radio . Commands ) ;
520
+ this . callback = stub ( ) ;
521
+ this . Commands . complyForOnce ( this . CommandsTwo , 'myCommand' , this . callback ) ;
522
+ this . CommandsTwo . command ( 'myCommand' ) ;
523
+ } ) ;
524
+
525
+ it ( 'should execute the callback with the correct context' , function ( ) {
526
+ expect ( this . callback )
527
+ . to . have . been . calledOnce
528
+ . and . to . have . always . been . calledOn ( this . Commands ) ;
529
+ } ) ;
530
+
531
+ it ( 'should remove the reference from the original object' , function ( ) {
532
+ expect ( this . CommandsTwo . _commands ) . to . deep . equal ( { } ) ;
533
+ } ) ;
534
+ } ) ;
478
535
} ) ;
0 commit comments