0

I'm using mocha for testing, when I code below, the test will get timeout:

describe("myTest", () => {
  it("myTest-0", async () => {
    await new Promise(async (res, rej) => {
      throw new Error("this is error");
    });
  });
});

enter image description here

=========================================================

but if I remove new Promise executor's async prefix, the test will throw error immediately:

describe("myTest", () => {
  it("myTest-0", () => {
    await new Promise(async (res, rej) => {
      throw new Error("this is error");
    });
  });
});

enter image description here

=========================================

why the first one get timeout instead of throwing error immediately?

suda moayui
  • 63
  • 2
  • 4
  • [Never pass an `async function` as the executor to `new Promise`](https://stackoverflow.com/q/43036229/1048572)! – Bergi Feb 18 '23 at 08:44
  • "*if I remove new Promise executor's async prefix*" - i think you removed the wrong `async` from your sample code. Please [edit] to fix – Bergi Feb 18 '23 at 08:45

0 Answers0