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)
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"