Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxying makes use order matter with chai-exclude and chai-as-promised #266

Open
kwasimensah opened this issue Jul 2, 2020 · 1 comment

Comments

@kwasimensah
Copy link

kwasimensah commented Jul 2, 2020

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.

@kwasimensah kwasimensah changed the title Use actual promises with eventually Proxying makes use order matter with chai-exclude and chai-as-promised Jul 3, 2020
@kwasimensah
Copy link
Author

kwasimensah commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant