Chai deep contains statement on nested objects

I am trying to claim that the object contains another (ei deep equal cannot be used), but it seems that the nested ones are checked strictly.

Code example:

describe('Meta', function () { it('object should contains a cloned copy', function () { var obj = {a: 1, b: '2', c: {a: 2, b: '2'}}; return expect(obj).deep.contains(JSON.parse(JSON.stringify(obj))); }); }); 

Error message:

 AssertionError: expected { a: 1, b: '2', c: { a: 2, b: '2' } } to have a property 'c' of { a: 2, b: '2' }, but got { a: 2, b: '2' } 

Is there a way to make "contains" with "deep equal" functions?

+6
source share
1 answer

Instead of using contains, try using eql:

 expect(obj).to.deep.eql(JSON.parse(JSON.stringify(obj))); 

eql compares values ​​in an object.

That should do the trick.

-1
source

Source: https://habr.com/ru/post/984495/


All Articles