I have these 2 tests
describe('the create() method ', (() => {
it('test#1 should fail if there is no code supplied', () => {
return foo.create({}) .should.be.rejected.and.eventually.to.have
.nested.property('details.codes.code[0]').that.eql('presence');
})
it('test #2 should fail if there is no code supplied', () => {
return foo.create({}).should.be.rejected.and.eventually.to.have
.deep.property('details.codes.code[0]','presence');
})
}))
When I run the test, I get the following result
the create() method
✓ test#1 should fail if there is no code supplied
1) test #2 should fail if there is no code supplied
1 passing (4s)
1 failing
1) when testing the foo model the create() method test #2 should fail if there is no code supplied:
AssertionError: expected { Object (name, message, ...) } to have deep property 'details.codes.code[0]'
is there something wrong with the way I am using deep.property ?
@jmls Starting with Chai v4, .nested enables the "nested syntax" (e.g., details.code.code[0]), and .deep enables deep equality comparison to be used as opposed to strict (===) comparison.
So for your second example... if the value of the property that you're checking is just a string, strict equality should be fine, so you don't need the .deep flag, you only need the .nested flag:
it('test #2 should fail if there is no code supplied', () => {
return foo.create({}).should.be.rejected.and.eventually.to.have
.nested.property('details.codes.code[0]','presence');
})
But if you were instead comparing the value against an object (e.g., {a: 1}) and wanted to use deep equality, then you would combine the .nested and .deep flags:
it('test #2 should fail if there is no code supplied', () => {
return foo.create({}).should.be.rejected.and.eventually.to.have
.deep.nested.property('details.codes.code[0]', {a: 1});
})
ok, cool. thanks for the explanation.
Most helpful comment
@jmls Starting with Chai v4,
.nestedenables the "nested syntax" (e.g.,details.code.code[0]), and.deepenables deep equality comparison to be used as opposed to strict (===) comparison.So for your second example... if the value of the property that you're checking is just a string, strict equality should be fine, so you don't need the
.deepflag, you only need the.nestedflag:But if you were instead comparing the value against an object (e.g.,
{a: 1}) and wanted to use deep equality, then you would combine the.nestedand.deepflags: