inspect-js / node-deep-equal

node's assert.deepEqual algorithm
MIT License
778 stars 109 forks source link

Equivalent objects with NaN values are treated as not equal #95

Closed nathan815 closed 1 year ago

nathan815 commented 3 years ago

Node version: 15.14.0 deep-equal version: 2.0.5

Test:

❯ node
Welcome to Node.js v15.14.0.
Type ".help" for more information.
> const deepEqual = require('deep-equal');
undefined
> deepEqual({ a: 123, b: NaN }, { a: 123, b: NaN })
false
>

I was expecting deep-equal to return true.

Node's assert.deepEqual says the above objects are equal:

> const assert = require('assert');
undefined
> assert.deepEqual({ a: 123, b: NaN }, { a: 123, b: NaN })
undefined

And this NaN unit test seems to assert that it returns true (?)

Is returning false the expected behavior?

ljharb commented 3 years ago

It depends on which node version you're checking. In node < 14, that assert example throws.

It would be a breaking change for deep-equal to make the same change; I noted this in 93679546.

In other words, in v3, this will change, but for now it's stuck with the node < 14 semantics.

nathan815 commented 3 years ago

@ljharb Ah, ok. Thanks!

Enabling the strict option makes it work like Node 14's assert.deepEqual for NaN values, so I'll just run it with that option.

ljharb commented 3 years ago

Right, it’s only loose equality where this applies.