-
Notifications
You must be signed in to change notification settings - Fork 632
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
assertEquals conflicts with the JavaScript's meaning of "equality" #3513
Comments
In Node assert.equal(NaN, NaN)
assert.strictEqual(NaN, NaN) Also in Jest, the below doesn't throw: expect(NaN).toEqual(NaN);
expect(NaN).toBe(NaN); I think assertion libs treating NaN equals itself is standard in JS ecosystem |
@kt3k good call in comparing to other frameworks. It's a bit of a rabbit hole. Here's what I found: Node
JestThe documentation is rather sparse, but both
ChaiThe
|
My gut feeling is that if someone cares about assert(maybeNaN() === anotherMaybeNaN()); Most developers do not know or care about I feel like this is more of an issue of documentation than of behavior. We should make sure that developers that DO care know that |
Unfortunately, I don't think that's the case. I do think
It's documentation AND naming. I think JavaScript as a language is at fault here. It screwed up with "equality" twice, and now the word is broken. For some reason, I'd maybe rename:
|
Closing due to the inactivity. |
Describe the bug
assertEquals
incorrectly treatsNaN
which as equal to itself.For reference, JavaScript has 3 similar operations for equivalence:
NaN == NaN # false
"loose equality"NaN === NaN # false
"strict equality"Object.is(NaN, NaN) # true
"same value"Steps to Reproduce
Expected behavior
As written, all three of the above assertions should fail. If the current
NaN
behavior is intended, it should be documented and/or renamed to something likeassertAlike
orassertSameValue
which doesn't conflict with Javascript's definitions of "equal".Environment
The text was updated successfully, but these errors were encountered: