Skip to content

Commit

Permalink
simpler way to sanitize date ranges for tests
Browse files Browse the repository at this point in the history
fixes #1072
No idea why deleting the extra members was not working (anymore?) on
Safari, but this way is much cleaner anyway (especially because it's not
modifying objects which are in use by the charts!)
  • Loading branch information
gordonwoodhull committed Dec 22, 2015
1 parent 03e06b1 commit 1369e13
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
6 changes: 2 additions & 4 deletions spec/bar-chart-spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global appendChartID, loadDateFixture, makeDate */
/* global appendChartID, loadDateFixture, makeDate, cleanDateRange */
describe('dc.barChart', function () {
var id, chart, data;
var dimension, group;
Expand Down Expand Up @@ -1047,9 +1047,7 @@ describe('dc.barChart', function () {

it('should not round the brush', function () {
jasmine.clock().tick(100);
var filter = chart.filter();
delete filter.isFiltered;
delete filter.filterType;
var filter = cleanDateRange(chart.filter());
expect(filter).toEqual([makeDate(2012, 6, 1), makeDate(2012, 7, 15)]);
});
});
Expand Down
14 changes: 4 additions & 10 deletions spec/coordinate-grid-chart-spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global appendChartID, loadDateFixture, makeDate */
/* global appendChartID, loadDateFixture, makeDate, cleanDateRange */
describe('dc.coordinateGridChart', function () {
var chart, id;
var data, dimension, group;
Expand Down Expand Up @@ -735,9 +735,7 @@ describe('dc.coordinateGridChart', function () {
});

it('should update chart filter to match new x domain', function () {
var filter = chart.filter();
delete filter.isFiltered;
delete filter.filterType;
var filter = cleanDateRange(chart.filter());
expect(filter).toEqual(chart.x().domain());
});

Expand Down Expand Up @@ -850,9 +848,7 @@ describe('dc.coordinateGridChart', function () {
rangeChart.brush().event(rangeChart.g());
jasmine.clock().tick(100);
// expect(chart.focus).toHaveBeenCalledWith(selectedRange);
var focus = chart.focus.calls.argsFor(0)[0];
delete focus.isFiltered;
delete focus.filterType;
var focus = cleanDateRange(chart.focus.calls.argsFor(0)[0]);
expect(focus).toEqual(selectedRange);
});

Expand All @@ -871,9 +867,7 @@ describe('dc.coordinateGridChart', function () {
spyOn(rangeChart, 'replaceFilter');
chart.focus(selectedRange);
// expect(rangeChart.replaceFilter).toHaveBeenCalledWith(selectedRange);
var replaceFilter = rangeChart.replaceFilter.calls.argsFor(0)[0];
delete replaceFilter.isFiltered;
delete replaceFilter.filterType;
var replaceFilter = cleanDateRange(rangeChart.replaceFilter.calls.argsFor(0)[0]);
expect(replaceFilter).toEqual(selectedRange);
});
});
Expand Down
6 changes: 6 additions & 0 deletions spec/helpers/spec-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ function makeDate (year, month, day) {
return new Date(Date.UTC(year, month, day, 0, 0, 0, 0));
}

// the invisible non-array members that we add in dc.filter cause the objects
// to be non-equal (correctly, but with no good diagnostics) in the eyes of Jasmine.
function cleanDateRange (range) {
return [range[0], range[1]];
}

// http://stackoverflow.com/questions/20068497/d3-transition-in-unit-testing
function flushAllD3Transitions () {
var now = Date.now;
Expand Down

0 comments on commit 1369e13

Please sign in to comment.