diff options
| author | Matias Niemelä | 2014-01-22 19:21:05 -0500 |
|---|---|---|
| committer | Matias Niemelä | 2014-02-06 01:21:41 -0500 |
| commit | 906fdad0f95465842e336e057ea97d0633712189 (patch) | |
| tree | 0993034fe2ce43ad090203c7d2390662536d1d91 /test/ng/directive/ngClassSpec.js | |
| parent | a8c1d9c97804f7df98150456c2702fd39e3a22f0 (diff) | |
| download | angular.js-906fdad0f95465842e336e057ea97d0633712189.tar.bz2 | |
fix(mocks): remove usage of $animate.flushNext in favour of queing
The flushNext method of testing is difficult and highly coupled with the behavior
of ngAnimate's $animate workflow. It is much better instead to just queue all
$animate animation calls into a queue collection which is available on the $animate
service when mock.animate is included as a module within test code.
Diffstat (limited to 'test/ng/directive/ngClassSpec.js')
| -rw-r--r-- | test/ng/directive/ngClassSpec.js | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/test/ng/directive/ngClassSpec.js b/test/ng/directive/ngClassSpec.js index 3e466068..976c0c3f 100644 --- a/test/ng/directive/ngClassSpec.js +++ b/test/ng/directive/ngClassSpec.js @@ -320,23 +320,23 @@ describe('ngClass animations', function() { $rootScope.val = 'one'; $rootScope.$digest(); - $animate.flushNext('addClass'); + expect($animate.queue.shift().event).toBe('addClass'); expect($animate.queue.length).toBe(0); $rootScope.val = ''; $rootScope.$digest(); - $animate.flushNext('removeClass'); //only removeClass is called + expect($animate.queue.shift().event).toBe('removeClass'); //only removeClass is called expect($animate.queue.length).toBe(0); $rootScope.val = 'one'; $rootScope.$digest(); - $animate.flushNext('addClass'); + expect($animate.queue.shift().event).toBe('addClass'); expect($animate.queue.length).toBe(0); $rootScope.val = 'two'; $rootScope.$digest(); - $animate.flushNext('removeClass'); - $animate.flushNext('addClass'); + expect($animate.queue.shift().event).toBe('removeClass'); + expect($animate.queue.shift().event).toBe('addClass'); expect($animate.queue.length).toBe(0); }); }); @@ -430,16 +430,18 @@ describe('ngClass animations', function() { $rootScope.$digest(); //this fires twice due to the class observer firing - className = $animate.flushNext('addClass').params[1]; - expect(className).toBe('one two three'); + var item = $animate.queue.shift(); + expect(item.event).toBe('addClass'); + expect(item.args[1]).toBe('one two three'); expect($animate.queue.length).toBe(0); $rootScope.three = false; $rootScope.$digest(); - className = $animate.flushNext('removeClass').params[1]; - expect(className).toBe('three'); + item = $animate.queue.shift(); + expect(item.event).toBe('removeClass'); + expect(item.args[1]).toBe('three'); expect($animate.queue.length).toBe(0); @@ -447,11 +449,13 @@ describe('ngClass animations', function() { $rootScope.three = true; $rootScope.$digest(); - className = $animate.flushNext('removeClass').params[1]; - expect(className).toBe('two'); + item = $animate.queue.shift(); + expect(item.event).toBe('removeClass'); + expect(item.args[1]).toBe('two'); - className = $animate.flushNext('addClass').params[1]; - expect(className).toBe('three'); + item = $animate.queue.shift(); + expect(item.event).toBe('addClass'); + expect(item.args[1]).toBe('three'); expect($animate.queue.length).toBe(0); }); |
