@@ -450,6 +450,102 @@ describe('jqLite', function(){
450
450
} ) ;
451
451
452
452
453
+ describe ( 'unbind' , function ( ) {
454
+ it ( 'should do nothing when no listener was registered with bound' , function ( ) {
455
+ var aElem = jqLite ( a ) ;
456
+
457
+ aElem . unbind ( ) ;
458
+ aElem . unbind ( 'click' ) ;
459
+ aElem . unbind ( 'click' , function ( ) { } ) ;
460
+ } ) ;
461
+
462
+
463
+ it ( 'should deregister all listeners' , function ( ) {
464
+ var aElem = jqLite ( a ) ,
465
+ clickSpy = jasmine . createSpy ( 'click' ) ,
466
+ mouseoverSpy = jasmine . createSpy ( 'mouseover' ) ;
467
+
468
+ aElem . bind ( 'click' , clickSpy ) ;
469
+ aElem . bind ( 'mouseover' , mouseoverSpy ) ;
470
+
471
+ browserTrigger ( a , 'click' ) ;
472
+ expect ( clickSpy ) . toHaveBeenCalledOnce ( ) ;
473
+ browserTrigger ( a , 'mouseover' ) ;
474
+ expect ( mouseoverSpy ) . toHaveBeenCalledOnce ( ) ;
475
+
476
+ clickSpy . reset ( ) ;
477
+ mouseoverSpy . reset ( ) ;
478
+
479
+ aElem . unbind ( ) ;
480
+
481
+ browserTrigger ( a , 'click' ) ;
482
+ expect ( clickSpy ) . not . toHaveBeenCalled ( ) ;
483
+ browserTrigger ( a , 'mouseover' ) ;
484
+ expect ( mouseoverSpy ) . not . toHaveBeenCalled ( ) ;
485
+ } ) ;
486
+
487
+
488
+ it ( 'should deregister listeners for specific type' , function ( ) {
489
+ var aElem = jqLite ( a ) ,
490
+ clickSpy = jasmine . createSpy ( 'click' ) ,
491
+ mouseoverSpy = jasmine . createSpy ( 'mouseover' ) ;
492
+
493
+ aElem . bind ( 'click' , clickSpy ) ;
494
+ aElem . bind ( 'mouseover' , mouseoverSpy ) ;
495
+
496
+ browserTrigger ( a , 'click' ) ;
497
+ expect ( clickSpy ) . toHaveBeenCalledOnce ( ) ;
498
+ browserTrigger ( a , 'mouseover' ) ;
499
+ expect ( mouseoverSpy ) . toHaveBeenCalledOnce ( ) ;
500
+
501
+ clickSpy . reset ( ) ;
502
+ mouseoverSpy . reset ( ) ;
503
+
504
+ aElem . unbind ( 'click' ) ;
505
+
506
+ browserTrigger ( a , 'click' ) ;
507
+ expect ( clickSpy ) . not . toHaveBeenCalled ( ) ;
508
+ browserTrigger ( a , 'mouseover' ) ;
509
+ expect ( mouseoverSpy ) . toHaveBeenCalledOnce ( ) ;
510
+
511
+ mouseoverSpy . reset ( ) ;
512
+
513
+ aElem . unbind ( 'mouseover' ) ;
514
+ browserTrigger ( a , 'mouseover' ) ;
515
+ expect ( mouseoverSpy ) . not . toHaveBeenCalled ( ) ;
516
+ } ) ;
517
+
518
+
519
+ it ( 'should deregister specific listener' , function ( ) {
520
+ var aElem = jqLite ( a ) ,
521
+ clickSpy1 = jasmine . createSpy ( 'click1' ) ,
522
+ clickSpy2 = jasmine . createSpy ( 'click2' ) ;
523
+
524
+ aElem . bind ( 'click' , clickSpy1 ) ;
525
+ aElem . bind ( 'click' , clickSpy2 ) ;
526
+
527
+ browserTrigger ( a , 'click' ) ;
528
+ expect ( clickSpy1 ) . toHaveBeenCalledOnce ( ) ;
529
+ expect ( clickSpy2 ) . toHaveBeenCalledOnce ( ) ;
530
+
531
+ clickSpy1 . reset ( ) ;
532
+ clickSpy2 . reset ( ) ;
533
+
534
+ aElem . unbind ( 'click' , clickSpy1 ) ;
535
+
536
+ browserTrigger ( a , 'click' ) ;
537
+ expect ( clickSpy1 ) . not . toHaveBeenCalled ( ) ;
538
+ expect ( clickSpy2 ) . toHaveBeenCalledOnce ( ) ;
539
+
540
+ clickSpy2 . reset ( ) ;
541
+
542
+ aElem . unbind ( 'click' , clickSpy2 ) ;
543
+ browserTrigger ( a , 'click' ) ;
544
+ expect ( clickSpy2 ) . not . toHaveBeenCalled ( ) ;
545
+ } ) ;
546
+ } ) ;
547
+
548
+
453
549
describe ( 'replaceWith' , function ( ) {
454
550
it ( 'should replaceWith' , function ( ) {
455
551
var root = jqLite ( '<div>' ) . html ( 'before-<div></div>after' ) ;
0 commit comments