node-deep-equal icon indicating copy to clipboard operation
node-deep-equal copied to clipboard

Equivalent objects with NaN values are treated as not equal

Open nathan815 opened this issue 4 years ago • 3 comments
trafficstars

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?

nathan815 avatar Sep 24 '21 05:09 nathan815

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.

ljharb avatar Sep 24 '21 05:09 ljharb

@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.

nathan815 avatar Sep 24 '21 15:09 nathan815

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

ljharb avatar Sep 24 '21 15:09 ljharb