6

I'm trying to assert that a object contains another one(e.i. deep equal cannot be use), 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 any way to do a "contains" with "deep equal" functionality?

Marc
  • 3,683
  • 8
  • 34
  • 48
Víctor Herraiz
  • 1,132
  • 1
  • 11
  • 26
  • Possible duplicate of [Chai assertion testing whether object structure contains at least other object structure](https://stackoverflow.com/questions/35101998/chai-assertion-testing-whether-object-structure-contains-at-least-other-object-s) – GolezTrol Oct 05 '17 at 21:25

1 Answers1

-1

Instead of using contains, try using eql:

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

eql compares the values in the object.

That should do the trick.

benka
  • 4,732
  • 35
  • 47
  • 58
pameck
  • 11
  • 2