You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 ?
The text was updated successfully, but these errors were encountered:
@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',()=>{returnfoo.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',()=>{returnfoo.create({}).should.be.rejected.and.eventually.to.have.deep.nested.property('details.codes.code[0]',{a: 1});})
I have these 2 tests
When I run the test, I get the following result
is there something wrong with the way I am using
deep.property
?The text was updated successfully, but these errors were encountered: