Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 24ed61c

Browse files
matskoIgorMinar
authored andcommitted
test($animator): ensure invalid $sniffer.transitions and $sniffer.animations flags are caught in animation spec code
1 parent 3a49b7e commit 24ed61c

File tree

1 file changed

+44
-12
lines changed

1 file changed

+44
-12
lines changed

test/ng/animatorSpec.js

+44-12
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ describe("$animator", function() {
386386
window.setTimeout.expect(1).process();
387387
window.setTimeout.expect(4000).process();
388388
}
389+
else {
390+
expect(window.setTimeout.queue.length).toBe(0);
391+
}
389392
expect(element[0].style.display).toBe('');
390393
}));
391394

@@ -408,6 +411,9 @@ describe("$animator", function() {
408411
window.setTimeout.expect(1).process();
409412
window.setTimeout.expect(6000).process();
410413
}
414+
else {
415+
expect(window.setTimeout.queue.length).toBe(0);
416+
}
411417
expect(element[0].style.display).toBe('');
412418
}));
413419

@@ -430,6 +436,9 @@ describe("$animator", function() {
430436
window.setTimeout.expect(1).process();
431437
window.setTimeout.expect(2000).process();
432438
}
439+
else {
440+
expect(window.setTimeout.queue.length).toBe(0);
441+
}
433442
expect(element[0].style.display).toBe('');
434443
}));
435444

@@ -454,6 +463,9 @@ describe("$animator", function() {
454463
window.setTimeout.expect(1).process();
455464
window.setTimeout.expect(20000).process();
456465
}
466+
else {
467+
expect(window.setTimeout.queue.length).toBe(0);
468+
}
457469
expect(element[0].style.display).toBe('');
458470
}));
459471

@@ -475,8 +487,6 @@ describe("$animator", function() {
475487

476488
it("should finish the previous animation when a new animation is started",
477489
inject(function($animator, $rootScope, $compile, $sniffer) {
478-
if(!$sniffer.animations) return;
479-
480490
var style = 'animation: some_animation 2s linear 0s 1 alternate;' +
481491
vendorPrefix + 'animation: some_animation 2s linear 0s 1 alternate;'
482492

@@ -486,11 +496,19 @@ describe("$animator", function() {
486496
});
487497

488498
animator.show(element);
489-
window.setTimeout.expect(1).process();
490-
expect(element.hasClass('show')).toBe(true);
491-
expect(element.hasClass('show-active')).toBe(true);
499+
if($sniffer.animations) {
500+
window.setTimeout.expect(1).process();
501+
expect(element.hasClass('show')).toBe(true);
502+
expect(element.hasClass('show-active')).toBe(true);
503+
}
504+
else { //animation is skipped
505+
expect(window.setTimeout.queue.length).toBe(0);
506+
}
492507

493508
animator.hide(element);
509+
if(!$sniffer.animations) {
510+
expect(window.setTimeout.queue.length).toBe(0);
511+
}
494512
expect(element.hasClass('show')).toBe(false);
495513
expect(element.hasClass('show-active')).toBe(false);
496514
}));
@@ -520,6 +538,9 @@ describe("$animator", function() {
520538
window.setTimeout.expect(1).process();
521539
window.setTimeout.expect(1000).process();
522540
}
541+
else {
542+
expect(window.setTimeout.queue.length).toBe(0);
543+
}
523544
expect(element[0].style.display).toBe('');
524545
}));
525546

@@ -536,6 +557,9 @@ describe("$animator", function() {
536557
window.setTimeout.expect(1).process();
537558
window.setTimeout.expect(2000).process();
538559
}
560+
else {
561+
expect(window.setTimeout.queue.length).toBe(0);
562+
}
539563
expect(element[0].style.display).toBe('');
540564
}));
541565

@@ -565,29 +589,37 @@ describe("$animator", function() {
565589
if ($sniffer.transitions) {
566590
window.setTimeout.expect(1).process();
567591
window.setTimeout.expect(3000).process();
568-
return;
592+
}
593+
else {
594+
expect(window.setTimeout.queue.length).toBe(0);
569595
}
570596
expect(element[0].style.display).toBe('');
571597
}));
572598

573599
it("should finish the previous transition when a new animation is started",
574600
inject(function($animator, $rootScope, $compile, $sniffer) {
575-
if(!$sniffer.animations) return;
576-
577601
var style = 'transition: 1s linear all;' +
578-
vendorPrefix + 'animation: 1s linear all;'
602+
vendorPrefix + 'transition: 1s linear all;'
579603

580604
element = $compile(html('<div style="' + style + '">1</div>'))($rootScope);
581605
var animator = $animator($rootScope, {
582606
ngAnimate : '{show: \'show\', hide: \'hide\'}'
583607
});
584608

585609
animator.show(element);
586-
window.setTimeout.expect(1).process();
587-
expect(element.hasClass('show')).toBe(true);
588-
expect(element.hasClass('show-active')).toBe(true);
610+
if($sniffer.transitions) {
611+
window.setTimeout.expect(1).process();
612+
expect(element.hasClass('show')).toBe(true);
613+
expect(element.hasClass('show-active')).toBe(true);
614+
}
615+
else { //animation is skipped
616+
expect(window.setTimeout.queue.length).toBe(0);
617+
}
589618

590619
animator.hide(element);
620+
if(!$sniffer.transitions) {
621+
expect(window.setTimeout.queue.length).toBe(0);
622+
}
591623
expect(element.hasClass('show')).toBe(false);
592624
expect(element.hasClass('show-active')).toBe(false);
593625
}));

0 commit comments

Comments
 (0)