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

235
Views
Assert an object to be deep equal to another with number or null field

I have this object,

obj1 = {
  a: 1,
  b: 2,
  c: 3 // or null,
}
obj2 = {
a: 1,
b: 2,
c: null // or 3
}

How can I assert deep equal on these object?

expect(obj1).to.deep.eql(obj2);

I know above doesn't work the way I want.

I need a or condition here that takes care of null or either number part.

I could do something like below.

expect(obj1.c).to.be.within([3, null])
delete obj1.c
delete obj2.c
expect(obj1).to.deep.eql(obj2)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use AND/OR logical operators of chai-json-pattern plugin.

const chai = require('chai');
const chaiJsonPattern = require('chai-json-pattern').default;
chai.use(chaiJsonPattern);

const { expect } = chai;

describe('69158740', () => {
  it('should pass', () => {
    const obj1 = { a: 1, b: 2, c: 3 };
    const obj2 = { a: 1, b: 2, c: null };
    expect(obj1).to.matchPattern(`{
      "a": 1,
      "b": 2,
      "c": null OR 3
    }`);
    expect(obj2).to.matchPattern(`{
      "a": 1,
      "b": 2,
      "c": null OR 3
    }`);
  });
});

package versions:

"chai-json-pattern": "^1.1.0",
"chai": "^4.2.0"
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!