Fail when one of the arguments passed into toBeCloseTo matcher is null

This commit is contained in:
Beat Richartz
2017-05-25 10:08:33 +01:00
parent 3372af1cf1
commit 271908a2c4
2 changed files with 22 additions and 0 deletions

View File

@@ -15,6 +15,12 @@ getJasmineRequireObj().toBeCloseTo = function() {
precision = precision || 2;
}
if (expected === null || actual === null) {
throw new Error('Cannot use toBeCloseTo with null. Arguments evaluated to: ' +
'expect(' + actual + ').toBeCloseTo(' + expected + ').'
);
}
return {
pass: Math.abs(expected - actual) < (Math.pow(10, -precision) / 2)
};