After reviewing various posts and documentation, I am struggling to understand why this code is not functioning as expected.
const chai = require('chai');
const expect = chai.expect;
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
async function foo(val) {
if (!val) {
const err = new Error();
err.status = 404;
throw err;
}
return new Promise(resolve => sleepSetTimeout_ctrl = setTimeout(resolve, 10));
}
describe('does not work', () => {
it('throws', async () => {
await expect(foo()).to.be.rejectedWith(Error).and.have.property('status');
});
});
When I stop the expect at rejectedWith(Error)
, everything works fine. However, when trying to test for the existence of a property, it fails with:
AssertionError: expected {} to have property 'status'