Chai: Deep property equality testing?

Created on 22 Jun 2012  路  4Comments  路  Source: chaijs/chai

I have recently written a few tests like this:

serverRequest.should.have.property("customerId", "abc");
serverRequest.should.have.property("clientId", "123");
serverRequest.should.have.property("scope");
serverRequest.scope.should.deep.equal(["foo", "bar"]);

Those last two lines are sad, but necessary since property does strict equality testing.

I was thinking maybe we should add a third boolean argument to property, that will do deep equality if true? Then it'd be

serverRequest.should.have.property("customerId", "abc");
serverRequest.should.have.property("clientId", "123");
serverRequest.should.have.property("scope", ["foo", "bar"], true);

I guess this is also a case for the properties assertion of #72, heh.

Thoughts?

Most helpful comment

Is this really necessary? We have setup property to behave differently by changing the subject of the assertion to be the value of whatever path your provide.

serverRequest.should.have.property('scope').to.deep.equal([ 'foo', 'bar' ]);

I have been wanting to add a that chainable, though.

All 4 comments

Is this really necessary? We have setup property to behave differently by changing the subject of the assertion to be the value of whatever path your provide.

serverRequest.should.have.property('scope').to.deep.equal([ 'foo', 'bar' ]);

I have been wanting to add a that chainable, though.

Ohhhhh totally didn't realize that would work :). Good call!!

I just realized that the docs don't cover that difference. Reopening to remind myself to improve doc examples for this in next release.

I know this is an old thread - but is there any equivalent of the above for the assert() API?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AnAppAMonth picture AnAppAMonth  路  3Comments

leifhanack picture leifhanack  路  4Comments

meeber picture meeber  路  5Comments

meeber picture meeber  路  4Comments

corybill picture corybill  路  4Comments