diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/AngularSpec.js | 4 | ||||
-rw-r--r-- | test/service/scopeSpec.js | 33 |
2 files changed, 37 insertions, 0 deletions
diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 81a4901b..53f62f00 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -110,6 +110,10 @@ describe('angular', function() { expect(equals(undefined, undefined)).toBe(true); }); + + it('should treat two NaNs as equal', function() { + expect(equals(NaN, NaN)).toBe(true); + }); }); describe('size', function() { diff --git a/test/service/scopeSpec.js b/test/service/scopeSpec.js index 71a27b33..6e8d78ff 100644 --- a/test/service/scopeSpec.js +++ b/test/service/scopeSpec.js @@ -305,6 +305,39 @@ describe('Scope', function() { root.$digest(); //trigger expect(listener).not.toHaveBeenCalled(); })); + + + it('should not infinitely digest when current value is NaN', inject(function($rootScope) { + $rootScope.$watch(function() { return NaN;}); + + expect(function() { + $rootScope.$digest(); + }).not.toThrow(); + })); + + + it('should always call the watchr with newVal and oldVal equal on the first run', + inject(function($rootScope) { + var log = []; + function logger(scope, newVal, oldVal) { + var val = (newVal === oldVal || (newVal !== oldVal && oldVal !== newVal)) ? newVal : 'xxx'; + log.push(val); + }; + + $rootScope.$watch(function() { return NaN;}, logger); + $rootScope.$watch(function() { return undefined;}, logger); + $rootScope.$watch(function() { return '';}, logger); + $rootScope.$watch(function() { return false;}, logger); + $rootScope.$watch(function() { return {};}, logger); + $rootScope.$watch(function() { return 23;}, logger); + + $rootScope.$digest(); + expect(isNaN(log.shift())).toBe(true); //jasmine's toBe and toEqual don't work well with NaNs + expect(log).toEqual([undefined, '', false, {}, 23]); + log = [] + $rootScope.$digest(); + expect(log).toEqual([]); + })); }); |