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

[Bug]: JEST gives no info when the promise returned by test function is interrupted by an error and never resolved/rejected #12382

Closed
SPiCaRiA opened this issue Feb 13, 2022 · 2 comments

Comments

@SPiCaRiA
Copy link

SPiCaRiA commented Feb 13, 2022

Version

27.5.1

Steps to reproduce

it('test1', () => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      throw new Error();
      resolve(1);
    });
  }).then((v) => expect(v).toBe(1));
});

Expected behavior

In this case, an error thrown in setTimeout interrupts the resolve(1) of the promise, so the promise will stay in <pending> state. However, I guess this "unwanted" error is expected to be presented to the user in some way.

Actual behavior

The error "disappears", without any hint on its existence. JEST simply stucks at running the test case (since the promise is never resolved), and ends after the default timeout is hit, and exits without any further information.

Additional context

No response

Environment

System:
    OS: Linux undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Binaries:
    Node: 14.17.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /bin/yarn
    npm: 7.17.0 - /bin/npm
npmPackages:
    jest: ^27.5.1 => 27.5.1
@SimenB
Copy link
Member

SimenB commented Feb 13, 2022

It's not possible in JS to inspect that state of a promise from the outside. It's up to your own code to make sure to properly resolve or reject any promise you return to Jest. The only thing Jest can do is time out.

In this case (I realize it's example code), wrap the content of the timeout in try-catch.

@SimenB SimenB closed this as completed Feb 13, 2022
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants