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

Add a config option for unhandledrejection behavior #1419

Closed
raycohen opened this issue Nov 27, 2019 · 3 comments
Closed

Add a config option for unhandledrejection behavior #1419

raycohen opened this issue Nov 27, 2019 · 3 comments

Comments

@raycohen
Copy link
Member

I have a large codebase with tests written with QUnit 1. While upgrading, a lot of them fail with QUnit 2.5 because it started considering unhandled rejections errors.

I can probably find a way to work around this, but I was wondering if the QUnit project would support a config option to go back to the old way of allowing unhandled rejections?

@rwjblue
Copy link
Contributor

rwjblue commented Dec 4, 2019

I'm definitely sympathetic to your situation, but I don't think we should have divergent behavior (between window.onerror handling and window.onunhandledRejection handling) here.

FWIW, as a work around while you work on fixing your test suite you should be able to do something like:

const KNOWN_REJECTIONS = [
  // list of known rejections in your test suite
  // as issues are fixed, you should remove entries
  // from this array
  //
  // the goal here is to ensure that no **knew** unhandled
  // rejections get added to the test suite, while the existing
  // ones are whittled away
];
const ORIG_QUNIT_UNHANDLED_REJECTION = QUnit.onUnhandledRejection;
QUnit.onUnhandledRejection = function(reason) {
  if (KNOWN_REJECTIONS.indexOf(reason.message) > -1) {
    // do nothing
  } else {
    return ORIG_QUNIT_UNHANDLED_REJECTION.call(QUnit, reason);
  }
};

This works because QUnit sets up a handler for the event that calls the QUnit.onUnhandledRejection method:

qunit/reporter/html.js

Lines 1059 to 1061 in d7f1e27

window.addEventListener( "unhandledrejection", function( event ) {
QUnit.onUnhandledRejection( event.reason );
} );

@raycohen
Copy link
Member Author

raycohen commented Dec 4, 2019

No problem. Thanks for the workaround suggestion!

@raycohen raycohen closed this as completed Dec 4, 2019
@NullVoxPopuli
Copy link
Contributor

properties on QUnit are read-only, so this approach is no longer viable.

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

No branches or pull requests

3 participants