Skip to content

Commit

Permalink
matcher toEqualIntList for dot-dash specs
Browse files Browse the repository at this point in the history
fixes #1064
  • Loading branch information
gordonwoodhull committed Dec 22, 2015
1 parent 9473156 commit b8622b9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
29 changes: 29 additions & 0 deletions spec/helpers/custom_matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function compareSubPath (got, wanted, i, j, delta) {
}
return {pass: true};
}

function comparePaths (actual, expected, delta) {
delta = delta || 1; // default delta of 1px
var got = parsePath(actual),
Expand All @@ -108,6 +109,7 @@ function comparePaths (actual, expected, delta) {
}
return compareSubPath(got, wanted, 0, 0, delta);
}

function findSubPath (actual, expected, delta) {
delta = delta || 1; // default delta of 1px
var got = parsePath(actual),
Expand All @@ -125,6 +127,28 @@ function findSubPath (actual, expected, delta) {
};
}

// actually number list, but presumably you'd want closeness if you need that
function compareIntList (actual, expected) {
var aparts = actual.split(/, */),
eparts = expected.split(/, */);
if (aparts.length !== eparts.length) {
return {
pass: false,
message: 'actual number of list items ' + aparts.length +
' did not match expected number ' + eparts.length
};
}
for (var i = 0; i < eparts.length; ++i) {
if (+aparts[i] !== +eparts[i]) {
return {
pass: false,
message: 'list item[' + i + '] value ' + aparts[i] + ' did not equal expected value ' + eparts[i]
};
}
}
return {pass: true};
}

beforeEach(function () {
jasmine.addMatchers({
toBeWithinDelta: function (_) {
Expand Down Expand Up @@ -179,6 +203,11 @@ beforeEach(function () {
return {
compare: findSubPath
};
},
toEqualIntList: function () {
return {
compare: compareIntList
};
}
});
});
4 changes: 2 additions & 2 deletions spec/legend-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ describe('dc.legend', function () {
});

it('should style legend line correctly', function () {
expect(legendLine(0).attr('stroke-dasharray')).toEqual('10,1');
expect(legendLine(1).attr('stroke-dasharray')).toEqual('2,1');
expect(legendLine(0).attr('stroke-dasharray')).toEqualIntList('10,1');
expect(legendLine(1).attr('stroke-dasharray')).toEqualIntList('2,1');
});
});

Expand Down
6 changes: 3 additions & 3 deletions spec/line-chart-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('dc.lineChart', function () {
});

it('should be dash-dot-dot-dot to match the specified style', function () {
expect(chart.selectAll('path.line').attr('stroke-dasharray')).toBe('3,1,1,1');
expect(chart.selectAll('path.line').attr('stroke-dasharray')).toEqualIntList('3,1,1,1');
});
});

Expand Down Expand Up @@ -195,8 +195,8 @@ describe('dc.lineChart', function () {
});

it('should have a stroke dash', function () {
expect(chart.selectAll('path.xRef').attr('stroke-dasharray')).toBe('5,5');
expect(chart.selectAll('path.yRef').attr('stroke-dasharray')).toBe('5,5');
expect(chart.selectAll('path.xRef').attr('stroke-dasharray')).toEqualIntList('5,5');
expect(chart.selectAll('path.yRef').attr('stroke-dasharray')).toEqualIntList('5,5');
});

describe('when dot is hovered over', function () {
Expand Down
4 changes: 2 additions & 2 deletions spec/series-chart-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ describe('dc.seriesChart', function () {
var lines = chart.selectAll('path.line');
var areas = chart.selectAll('path.area');

expect(d3.select(lines[0][0]).attr('stroke-dasharray')).toBe('3,1,1');
expect(d3.select(lines[0][1]).attr('stroke-dasharray')).toBe('3,1,1');
expect(d3.select(lines[0][0]).attr('stroke-dasharray')).toEqualIntList('3,1,1');
expect(d3.select(lines[0][1]).attr('stroke-dasharray')).toEqualIntList('3,1,1');

expect(d3.select(areas[0][0]).attr('fill')).toBe('#000001');
expect(d3.select(areas[0][1]).attr('fill')).toBe('#000002');
Expand Down

0 comments on commit b8622b9

Please sign in to comment.