I have a function that inserts into a table and returns a Promise
. I am testing with chai-as-promised
that duplicate inserts are rejected. What I want to test is the rejection, and the reason code. When I run the function and log console.log(err.reason.code)
I get ER_DUP_ENTRY
. Confirming this is sufficient for my test so I try to assert it as follows:
expect(insertTable()).to.eventually.be.rejected.and.eventually.to.have.deep.property('reason',{code: 'ER_DUP_ENTRY'}).notify(done);
The syntax seems to be correct, according to chaijs. But I get a failed test:
AssertionError: expected { Object (status, reason) } to have deep property 'reason' of { code: 'ER_DUP_ENTRY' }, but got [Error: ER_DUP_ENTRY: Duplicate entry 'my_dupe' for key 'name_UNIQUE']
This seems contradictory of what my console log says the property is.