aboutsummaryrefslogtreecommitdiffstats
path: root/test/JsonSpec.js
diff options
context:
space:
mode:
authorIgor Minar2012-03-26 23:38:20 -0700
committerIgor Minar2012-03-28 16:30:30 -0700
commitac4318a2fa5c6d306dbc19466246292a81767fca (patch)
treea8d9d0ff164516b153bf4c9142d1c9fb17315008 /test/JsonSpec.js
parentbb2fa6f63f0a4a08d4a3a5439d1ab6d9ddfd917e (diff)
downloadangular.js-ac4318a2fa5c6d306dbc19466246292a81767fca.tar.bz2
refactor(fromJson/date filter): move date string logic to date filter
Breaks angular.fromJson which doesn't deserialize date strings into date objects. This was done to make fromJson compatible with JSON.parse. If you do require the old behavior - if at all neeeded then because of json deserialization of XHR responses - then please create a custom $http transform: $httpProvider.defaults.transformResponse.push(function(data) { // recursively parse dates from data object here // see code removed in this diff for hints }); Closes #202
Diffstat (limited to 'test/JsonSpec.js')
-rw-r--r--test/JsonSpec.js52
1 files changed, 1 insertions, 51 deletions
diff --git a/test/JsonSpec.js b/test/JsonSpec.js
index e4abeef9..ad0cb415 100644
--- a/test/JsonSpec.js
+++ b/test/JsonSpec.js
@@ -72,9 +72,8 @@ describe('json', function() {
});
it('should serialize UTC dates', function() {
- var date = jsonStringToDate('2009-10-09T01:02:03.027Z');
+ var date = new angular.mock.TzDate(-1, '2009-10-09T01:02:03.027Z');
expect(toJson(date)).toEqual('"2009-10-09T01:02:03.027Z"');
- expect(fromJson('"2009-10-09T01:02:03.027Z"').getTime()).toEqual(date.getTime());
});
it('should prevent recursion', function() {
@@ -156,17 +155,7 @@ describe('json', function() {
expect(fromJson('{}', true)).toEqual({});
expect(spy).toHaveBeenCalled();
});
-
-
- it('should convert timestamp strings to Date objects', function() {
- expect(fromJson('"2010-12-22T17:23:17.974Z"', true) instanceof Date).toBe(true);
- expect(fromJson('["2010-12-22T17:23:17.974Z"]', true)[0] instanceof Date).toBe(true);
- expect(fromJson('{"t":"2010-12-22T17:23:17.974Z"}', true).t instanceof Date).toBe(true);
- expect(fromJson('{"t":["2010-12-22T17:23:17.974Z"]}', true).t[0] instanceof Date).toBe(true);
- expect(fromJson('{"t":{"t":"2010-12-22T17:23:17.974Z"}}', true).t.t instanceof Date).toBe(true);
- });
});
-
}
@@ -220,45 +209,6 @@ describe('json', function() {
});
- describe('iso 8061 date', function() {
- it('should read/write to date', function() {
- var date = new Date('Sep 10 2003 13:02:03 GMT');
- expect(jsonDateToString(date)).toBe('2003-09-10T13:02:03.000Z');
- expect(jsonStringToDate(jsonDateToString(date)).getTime()).toBe(date.getTime());
- });
-
-
- it('should convert to date', function() {
- //full ISO8061
- expect(jsonStringToDate('2003-09-10T13:02:03.000Z')).toEqual(new Date('Sep 10 2003 13:02:03 GMT'));
-
- expect(jsonStringToDate('2003-09-10T13:02:03.000+00:00')).toEqual(new Date('Sep 10 2003 13:02:03 GMT'));
-
- expect(jsonStringToDate('20030910T033203-0930')).toEqual(new Date('Sep 10 2003 13:02:03 GMT'));
-
- //no millis
- expect(jsonStringToDate('2003-09-10T13:02:03Z')).toEqual(new Date('Sep 10 2003 13:02:03 GMT'));
-
- //no seconds
- expect(jsonStringToDate('2003-09-10T13:02Z')).toEqual(new Date('Sep 10 2003 13:02:00 GMT'));
-
- //no minutes
- expect(jsonStringToDate('2003-09-10T13Z')).toEqual(new Date('Sep 10 2003 13:00:00 GMT'));
-
- //no time
- expect(jsonStringToDate('2003-09-10')).toEqual(new Date('Sep 10 2003 00:00:00 GMT'));
-
- expect(jsonStringToDate('2011-12-28T13:02:09-08:00')).toEqual(new Date('Dec 28 2011 21:02:09 GMT'));
- });
-
-
- it('should parse date', function() {
- var date = jsonStringToDate('2003-09-10T13:02:03.000Z');
- expect(jsonDateToString(date)).toBe('2003-09-10T13:02:03.000Z');
- expect(jsonStringToDate('str')).toBe('str');
- });
- });
-
describe('string', function() {
it('should quote', function() {
expect(quoteUnicode('a')).toBe('"a"');