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
"expect.eventually" returns a Chai.PromisedAssertion which doesn't warn when using await. Which means "await expect(myPromise).eventually.to.equal(arg)" will throw UnhandledPromiseRejectionWarning if the assertion is wrong but the test will still succeed.
if expect.eventually actually returns a promise it should be safe to use with await.
The text was updated successfully, but these errors were encountered:
kwasimensah
changed the title
Use actual promises with eventually
Proxying makes use order matter with chai-exclude and chai-as-promised
Jul 3, 2020
I figured out my actual issue. Both extensions do proxying on equal/equals. If chaiAsPromised isn't last, the proxy from chaiExclude drops information about the subject being a promise. Runkit at https://runkit.com/kwasimensah/5efdfbea19e9950013f020e0
const chai = require("chai")
const chaiAsPromised = require("chai-as-promised");
const chaiExclude = require("chai-exclude")
//Passes in this order
chai.use(chaiExclude);
chai.use(chaiAsPromised);
// Causes UnhandledPromiseRejectionWarning in this order
//chai.use(chaiAsPromised);
//chai.use(chaiExclude);
const expect = chai.expect;
const promiseA = new Promise((resolve) => {
setTimeout(()=>{
resolve(null);
}, 1000);
});
async function main(){
const bug = expect(promiseA).to.eventually.equal(6)
console.trace(bug.then);
await bug;
}
main().catch(err=>{});
More specifically, chai-excludes's assertEqual returns undefined, which means overwritingMethodWrapper creates newAssertion which drops the then attribute that transferPromisness added to the current assertion.
I filed the the Typescript side of this at microsoft/TypeScript#39387.
"expect.eventually" returns a Chai.PromisedAssertion which doesn't warn when using await. Which means "await expect(myPromise).eventually.to.equal(arg)" will throw UnhandledPromiseRejectionWarning if the assertion is wrong but the test will still succeed.
if expect.eventually actually returns a promise it should be safe to use with await.
The text was updated successfully, but these errors were encountered: