diff options
| author | Igor Minar | 2012-03-28 12:21:07 -0700 | 
|---|---|---|
| committer | Igor Minar | 2012-03-28 16:57:34 -0700 | 
| commit | af0ad6561c0d75c4f155b07e9cfc36a983af55bd (patch) | |
| tree | 8d1ddb4747553cb79d43332025a757b31c47f67f /test/AngularSpec.js | |
| parent | 35125d25137ac2da13ed1ca3e652ec8f2c945053 (diff) | |
| download | angular.js-af0ad6561c0d75c4f155b07e9cfc36a983af55bd.tar.bz2 | |
refactor(fromJson/toJson): move the contents of these files into Angular.js
these files are now mostly empty so it doesn't make sense to keep them
separated from other helper functions
Diffstat (limited to 'test/AngularSpec.js')
| -rw-r--r-- | test/AngularSpec.js | 50 | 
1 files changed, 50 insertions, 0 deletions
| diff --git a/test/AngularSpec.js b/test/AngularSpec.js index cb0c5c6b..da56449a 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -542,4 +542,54 @@ describe('angular', function() {        expect(snake_case('alanBobCharles')).toEqual('alan_bob_charles');      });    }); + + +  describe('fromJson', function() { + +    it('should delegate to JSON.parse', function() { +      var spy = spyOn(JSON, 'parse').andCallThrough(); + +      expect(fromJson('{}')).toEqual({}); +      expect(spy).toHaveBeenCalled(); +    }); +  }); + + +  describe('toJson', function() { + +    it('should delegate to JSON.stringify', function() { +      var spy = spyOn(JSON, 'stringify').andCallThrough(); + +      expect(toJson({})).toEqual('{}'); +      expect(spy).toHaveBeenCalled(); +    }); + + +    it('should format objects pretty', function() { +      expect(toJson({a: 1, b: 2}, true)). +          toBeOneOf('{\n  "a": 1,\n  "b": 2\n}', '{\n  "a":1,\n  "b":2\n}'); +      expect(toJson({a: {b: 2}}, true)). +          toBeOneOf('{\n  "a": {\n    "b": 2\n  }\n}', '{\n  "a":{\n    "b":2\n  }\n}'); +    }); + + +    it('should not serialize properties starting with $', function() { +      expect(toJson({$few: 'v', $$some:'value'}, false)).toEqual('{}'); +    }); + + +    it('should not serialize $window object', function() { +      expect(toJson(window)).toEqual('"$WINDOW"'); +    }); + + +    it('should not serialize $document object', function() { +      expect(toJson(document)).toEqual('"$DOCUMENT"'); +    }); + + +    it('should not serialize scope instances', inject(function($rootScope) { +      expect(toJson({key: $rootScope})).toEqual('{"key":"$SCOPE"}'); +    })); +  });  }); | 
