`ErrorEvent` test suite

by James Greene

HTML

<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.12.0.css">
<script src="http://code.jquery.com/qunit/qunit-1.12.0.js"></script>
<div id="qunit"></div>
<!--

SPECS:
  - http://www.w3.org/html/wg/drafts/html/master/webappapis.html#runtime-script-errors
  - http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#the-errorevent-interface

OTHER DOCS:
  - https://mikewest.org/2013/08/debugging-runtime-errors-with-window-onerror
  - https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent'

-->

JavaScript

// Force these options by automatically reloading the page.
// To bypass these (no good reason to do so), just add some other query string, e.g. "?bypass"
if (window.location.search.length <= 1) {
    window.location.search = "?noglobals=true&notrycatch=true";
}

// Set the test suite title
var titleEl = document.getElementsByTagName("title")[0];
document.title = titleEl.innerHTML = "`ErrorEvent` test suite";

// Polyfill `QUnit.assert.expect`
if (!QUnit.assert.expect) {
    QUnit.assert.expect = QUnit.expect;
}

// Demand that the expected number of assertions are explicitly declared
QUnit.config.requireExpects = true;


(function (module, test) {

    var hasErrorEvent = typeof window.ErrorEvent !== "undefined" && window.ErrorEvent !== null;
    var canAddListener = typeof window.addEventListener !== "undefined" && window.addEventListener !== null;
    var canRemoveListener = typeof window.removeEventListener !== "undefined" && window.removeEventListener !== null;

    module("Prerequisites");

    test("Has `ErrorEvent`", function (assert) {
        assert.expect(1);
        assert.strictEqual(hasErrorEvent, true, "`ErrorEvent` is unsupported.");
    });
    
    test("Has `window.addEventListener`", function (assert) {
        assert.expect(1);
        assert.strictEqual(canAddListener, true, "`window.addEvenListener` is unsupported.");
    });
    
    test("Has window.removeEventListener", function (assert) {
        assert.expect(1);
        assert.strictEqual(canRemoveListener, true, "`window.removeEvenListener` is unsupported.");
    });

    // Bail on the rest of the tests if the browser doesn't meet all of the prerequisites
    if (!(hasErrorEvent && canAddListener && canRemoveListener)) {
        return;
    }


    // GET HELPER FUNCTIONS
    var Helper = createHelper();
    

    //
    // TESTS A-GO-GO!
    //
    
    module("Execution order: `window.onerror` should always fire last", {
        setup: function (assert) {
           ...