Chai-as-promised checks against a promise--not its resolved value. While writing up some Promise
-based code, one might be accuomsted to always adding an await
when handling the Promise
. This rule therefore prohibits use of await
within chai-as-promised
-style conditions.
Examples of incorrect code for this rule:
it('should ...', async function() {
return expect(await promise).to.eventually.deep.equal("foo");
});
it('should ...', async function() {
await expect(await promise).to.eventually.deep.equal("foo");
});
it('should ...', async function() {
return expect(await promise).to.be.rejectedWith(Error);
});
it('should ...', async function() {
return (await promise).should.eventually.deep.equal("foo");
});
it('should ...', async function() {
return assert.isFulfilled(await promise, "optional message");
});
Examples of correct code for this rule:
it('should ...', async function() {
return expect(promise).to.eventually.deep.equal("foo");
});
it('should ...', async function() {
await expect(promise).to.eventually.deep.equal("foo");
});
it('should ...', async function() {
return expect(promise).to.be.rejectedWith(Error);
});
it('should ...', async function() {
return promise.should.eventually.deep.equal("foo");
});
it('should ...', async function() {
return assert.isFulfilled(promise, "optional message");
});
it('should ...', async function() {
// This is ok since the chain is not a `chai-as-promised` one
return expect(await promise).to.be.true;
});