Skip to content
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

strictEqual / deepStrictEqual behave differently on numbers #1532

Open
rotu opened this issue Aug 3, 2023 · 6 comments
Open

strictEqual / deepStrictEqual behave differently on numbers #1532

rotu opened this issue Aug 3, 2023 · 6 comments
Labels

Comments

@rotu
Copy link

rotu commented Aug 3, 2023

Chai's behavior of strictEqual and deepStrictEqual differ in how they treat numbers (particularly NaN and -0). It seems like "depth" should not affect the equality of two shallow objects.

chai.assert.strictEqual(NaN,NaN) // fails
chai.assert.deepStrictEqual(NaN,NaN) // passes

chai.assert.strictEqual(-0,0) // passes
chai.assert.deepStrictEqual(-0,0) // fails

Note that the documentation adds confusion, since it says that "deep equality" refers to deep-eql semantics and "strict equality" refers to ===:

* By default, strict (`===`) equality is used. Add `.deep` earlier in the
* chain to use deep equality instead. See the `deep-eql` project page for
* info on the deep equality algorithm: https://github.com/chaijs/deep-eql.

It appears deepStrictEqual was originally added as an alias for strictEqual to match Node: #653

@koddsson
Copy link
Member

Damn this is weird. I feel like chai.assert.strictEqual(NaN,NaN) and should not fail and chai.assert.strictEqual(-0,0) should not pass.

I'll dig into this.

cc/ @keithamus as someone that might know if this behaviour is actually correct.

@koddsson
Copy link
Member

I guess NaN !== NaN so it does make some sort of sense.

@koddsson
Copy link
Member

Also -0 === 0 now that I think about it.

@koddsson
Copy link
Member

Then reading the deep-eql README, it says:

  • Strict equality for non-traversable nodes according to Object.is:
    . - eql(NaN, NaN).should.be.true;
    . - eql(-0, +0).should.be.false;

@koddsson
Copy link
Member

Makes me think this is indeed working as expected but maybe a bit confusing.

@rotu
Copy link
Author

rotu commented Jan 28, 2024

Makes me think this is indeed working as expected but maybe a bit confusing.

I don't know what you mean by "as expected". The discrepancy was not the result of a typo, but it's also not a reasonable design choice.

I think I would expect chai to change strictEqual as node:assert did in v10. See relevant Node PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants