-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Non numbers shouldn't be used for the almost-equal check #18
Comments
Hey @TN1ck thanks for the issue. I'm not sure we should change this behaviour. I think it'd be better for you to change your assertion to only assert on the numeric keys. Thoughts? |
Yes, it's not clear what the correct way should be. But it feels strange when equal values aren't considered as equal, a error-message with |
That error message sounds like it could indeed be useful. Do you fancy making a pull request to this effect? |
I had this issue but I wasn't able to find a good way to pass in only numbers/objects. I ended up patching the exports.deepAlmostEqual = function(a,b,precision){
var tol = tolerance(precision);
function deepEql (act, exp) {
if (Object(act) === act){
for (var k in act) {
if (typeof act[k] === typeof exp[k] && (typeof act[k] === 'number'
|| typeof act[k] === 'object')) {
if (!(deepEql(act[k], exp[k]))) {
return false;
}
} else {
if (act[k] !== exp[k]) {
return false;
}
}
}
return true;
} else {
return Math.abs(act - exp) < tol;
}
}
return deepEql(a,b);
}; |
Writing a assertion like the following, will fail, because the library expects only numbers. I expected it only looks at the numbers, not at strings or other objects.
The text was updated successfully, but these errors were encountered: