Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
Is there an `assert.deepEqual` that uses _non-strict_ equality for JavaScript?

I have reason to test eg. [ { valueOf: ()=>0 } ] to [ 0 ] and want that test to succeed.

Node assert, and Chai's various interfaces, all seem to automatically use strict equality when doing deep equality tests.

Is there an assert.deepEqual that will not do an assert.deepStrictEqual somewhere? A deep analog of assert.equal instead of assert.strictEqual ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

All right, developing insight: it can't be done generally.

deepEqual will compare "all own and inherited enumerable object properties", and it will ( I am assuming here ) recursively descend on object properties until it encounters primitive values.

It has no reason to stop after the first level ( the array ), when encountering the second level ( the object ). The fact that my data actually has the encoding at the Object level is specific to my use case, and can not be assumed for the general case.

When arriving at primitive values for properties, then equality can generally usefully be non-strict.

The fact that an Object has a valueOf property ( which may or may not even be enumerable ) does not mean it should be treated as a primitive instead of an Object. Lots of things have a valueOf property.

The difference between deepEqual and equal is that equal knows it should be comparing two primitives ( or references ), and deepEqual can never know.

I was assuming too much, and asking the wrong question. Sorry SO.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!