Skip to content

Commit a2ad253

Browse files
committed
test-assets: don't try to compute dist between non-numeric elements
1 parent b9b1145 commit a2ad253

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

test/jasmine/assets/custom_matchers.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
'use strict';
2+
3+
var isNumeric = require('fast-isnumeric');
4+
5+
16
module.exports = {
27

38
// toBeCloseTo... but for arrays
@@ -7,7 +12,7 @@ module.exports = {
712
precision = coercePosition(precision);
813

914
var tested = actual.map(function(element, i) {
10-
return Math.abs(expected[i] - element) < precision;
15+
return isClose(element, expected[i], precision);
1116
});
1217

1318
var passed = (
@@ -44,9 +49,7 @@ module.exports = {
4449
}
4550

4651
for(var j = 0; j < expected[i].length; ++j) {
47-
var isClose = Math.abs(expected[i][j] - actual[i][j]) < precision;
48-
49-
if(!isClose) {
52+
if(!isClose(actual[i][j], expected[i][j], precision)) {
5053
passed = false;
5154
break;
5255
}
@@ -71,6 +74,14 @@ module.exports = {
7174
}
7275
};
7376

77+
function isClose(actual, expected, precision) {
78+
if(isNumeric(actual) && isNumeric(expected)) {
79+
return Math.abs(actual - expected) < precision;
80+
}
81+
82+
return actual === expected;
83+
}
84+
7485
function coercePosition(precision) {
7586
if(precision !== 0) {
7687
precision = Math.pow(10, -precision) / 2 || 0.005;

0 commit comments

Comments
 (0)