Skip to content

Commit ec0442c

Browse files
author
James Gibson
committed
Make assert.epsilon fail for NaN actual value
It makes sense than NaN would not be within a tolerance of a number. but since Math.abs(NaN) = NaN and NaN > x evalutes to false for all numeric x, assert.epsilon will pass if NaN is passed as the 'actual' argument. I could not determine how to use vows to assert that an assertion would fail, so there is no test case for this change, but the existing tests pass. I'm not sure asserting that an assertion will fail is possible with the library's promise-oriented design. This bug was originally found while working on the jStat project which relies on vows; if the vows team does not want to make assert.epsilon fail for NaN actual value, it would be good to have an additional method that would check both that the argument is a number and within the tolerance.
1 parent 64857e3 commit ec0442c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/assert/macros.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ for (var key in messages) {
1717
}
1818

1919
assert.epsilon = function (eps, actual, expected, message) {
20-
if (Math.abs(actual - expected) > eps) {
20+
if (isNaN(actual) || Math.abs(actual - expected) > eps) {
2121
assert.fail(actual, expected, message || "expected {expected} \u00B1"+ eps +", but was {actual}");
2222
}
2323
};

0 commit comments

Comments
 (0)