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

UnhandledPromiseRejectionWarning #11

Closed
andrewvsk opened this issue Jan 14, 2019 · 0 comments
Closed

UnhandledPromiseRejectionWarning #11

andrewvsk opened this issue Jan 14, 2019 · 0 comments
Assignees

Comments

@andrewvsk
Copy link

andrewvsk commented Jan 14, 2019

Wrong Promise rejection implementation:

assert() just throws exception and DOESN'T reject Promise that we expect in out test.
In this case sometimes we see UnhandledPromiseRejectionWarning.

Case 1

  const eventEmitter = new EventEmitter();
  const onEventA = expect(eventEmitter).to.not.emit('eventA');
  eventEmitter.emit('eventA');  // <--- HERE we get exception from on() handler
  await onEventA;               //  NOT HERE !
});

Case 2

  const eventEmitter = new EventEmitter();
  const onEventA = expect(eventEmitter).to.emit('eventA');

  await onEventA;                 // Promise will be NEVER resolved
  // Test fails only because setTimeout throws an error and mocha handles it
});

Tech details

Possible solution
Use try-catch for setTimeout() and on() handlers:

try {
    assert(...);
    resolve(args);
} catch (err) {
    reject(err);
}
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

2 participants