Skip to content

Commit 6440d81

Browse files
committed
fix(Tests): Date() usage failing on Safari 5
Safari is bailing on things like `new Date('2009-12-12'). According to SO it looks its date parsers doesn't like the hashes. This change uses the standard argument-based method of date creation. Additionally, Safari 5 appears to offset the timezone inappropriately. This change also uses .toISOString() for date string comparisons, rather than using the explicit typed-out date string.
1 parent 4bb2d69 commit 6440d81

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/features/exporter/test/exporter.spec.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,17 @@ describe('ui.grid.exporter uiGridExporterService', function () {
176176
{name: 'col3', displayName: 'Col3', width: 100, align: 'left'},
177177
{name: 'x', displayName: '12345234', width: 200, align: 'left'}
178178
];
179+
180+
var date = new Date(2014, 11, 12, 0, 0, 0, 0);
181+
179182
var data = [
180183
[ 'a string', 'a string', 'A string', 'a string' ],
181184
[ '', '45', 'A string', false ],
182-
[ new Date('2014-12-12'), 45, 'A string', true ]
185+
[ date, 45, 'A string', true ]
183186
];
184187

185188
expect(uiGridExporterService.formatAsCsv(columnHeaders, data)).toEqual(
186-
'"Col1","Col2","Col3","12345234"\n"a string","a string","A string","a string"\n"","45","A string",FALSE\n"2014-12-12T00:00:00.000Z",45,"A string",TRUE'
189+
'"Col1","Col2","Col3","12345234"\n"a string","a string","A string","a string"\n"","45","A string",FALSE\n"' + date.toISOString() + '",45,"A string",TRUE'
187190
);
188191
});
189192
});
@@ -233,10 +236,13 @@ describe('ui.grid.exporter uiGridExporterService', function () {
233236
{name: 'col3', displayName: 'Col3', width: 100, align: 'left'},
234237
{name: 'x', displayName: '12345234', width: 200, align: 'left'}
235238
];
239+
240+
var date = new Date(2014, 11, 12, 0, 0, 0, 0);
241+
236242
var data = [
237243
[ 'a string', 'a string', 'A string', 'a string' ],
238244
[ '', '45', 'A string', false ],
239-
[ new Date('2014-12-12'), 45, 'A string', true ]
245+
[ date, 45, 'A string', true ]
240246
];
241247

242248
var result = uiGridExporterService.prepareAsPdf(grid, columnHeaders, data);
@@ -256,7 +262,7 @@ describe('ui.grid.exporter uiGridExporterService', function () {
256262
],
257263
[ 'a string', 'a string', 'A string', 'a string' ],
258264
[ '', '45', 'A string', 'FALSE' ],
259-
[ "2014-12-12T00:00:00.000Z", '45', 'A string', 'TRUE' ]
265+
[ date.toISOString(), '45', 'A string', 'TRUE' ]
260266
]
261267
}
262268
}],
@@ -295,10 +301,13 @@ describe('ui.grid.exporter uiGridExporterService', function () {
295301
{name: 'col3', displayName: 'Col3', width: 100, align: 'left'},
296302
{name: 'x', displayName: '12345234', width: 200, align: 'left'}
297303
];
304+
305+
var date = new Date(2014, 12, 12, 0, 0, 0, 0);
306+
298307
var data = [
299308
[ 'a string', 'a string', 'A string', 'a string' ],
300309
[ '', '45', 'A string', false ],
301-
[ new Date('2014-12-12'), 45, 'A string', true ]
310+
[ date, 45, 'A string', true ]
302311
];
303312

304313
var result = uiGridExporterService.prepareAsPdf(grid, columnHeaders, data);
@@ -318,7 +327,7 @@ describe('ui.grid.exporter uiGridExporterService', function () {
318327
],
319328
[ 'a string', 'a string', 'A string', 'a string' ],
320329
[ '', '45', 'A string', 'FALSE' ],
321-
[ '2014-12-12T00:00:00.000Z', '45', 'A string', 'TRUE' ]
330+
[ date.toISOString(), '45', 'A string', 'TRUE' ]
322331
]
323332
}
324333
} ],

test/unit/core/row-sorting.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ describe('rowSorter', function() {
243243
sortNumber: [ undefined, null, 1, 2 ],
244244
sortNumberStr: [ undefined, null, '3.a5', '5.b7' ],
245245
sortAlpha: [ undefined, null, 'a', 'b' ],
246-
sortDate: [ undefined, null, new Date('2009-12-12'), new Date('2010-11-11') ],
246+
sortDate: [ undefined, null, new Date(2009, 12, 12), new Date(2010, 11, 11) ],
247247
sortBool: [ undefined, null, false, true ]
248248
};
249249

0 commit comments

Comments
 (0)