-
-
Notifications
You must be signed in to change notification settings - Fork 698
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
deep.equal assetion between function? #697
Comments
Hey @chentsulin thanks for the issue. I have two points to make on this:
// Are these the same?
const foo = (x) => x;
const bar = (x) => { return x };
function baz(x) { return x }
// They have the same behaviours but different string representations
foo.toString() === 'function (x) => x'
bar.toString() === 'function (x) => { return x }'
baz.toString() === 'function baz(x) { return x }'
// Are these the same?
const foo = (x) => {
// foo
return x;
}
const bar = (x) => {
// bar
return x;
}
// They also are identical in behaviour, but return different strings:
foo.toString() === '(x) => {\n // foo\n return x;\n}';
bar.toString() === '(x) => {''n // bar\n return x;\n}'; Hopefully this illustrates the minefield that would be comparing functions by source. If a function has the same source, it is likely the same reference. However, I'm going to go on a hunch and suggest you take a look at #644 which might solve the problems you're having in your tests. We will eventually have a matcher API whereby you can make loose assertions inside deep.equal, including on functions. I'll close this issue - because I'm pretty sure you want #644. If not, then I think realistically we won't support loose equality on functions because of the above 2 points. Feel free to continue the discussion here, or in #644 if you have ideas there. |
This just had me waste two days on failing tests. This should be explicitly called out on the docs, it's easy to slide right past the implications. :( |
When I try to use
deep.equal
assertion between functionI got a
AssertionError
Is this a expected behavior? When not just use
.toString()
to compare between functions?The text was updated successfully, but these errors were encountered: