I recently implemented a custom global error handler in my codebase, and I wanted to test its behavior in my QUnit+Sinon suite; however, this does not seem to work:
QUnit.test("It should fire an ajax request on errors", function(assert) {
var done = assert.async();
var myOnerror = window.onerror;
window.onerror = function(msg, url, line, col, error) {
myOnerror(msg, url, line, col, error);
//Some assertions on myOnerror execution
done();
};
banana(); //Trigger an error to have window.onerror execute
});
Since the ReferenceError caused by the banana() invocation is actually caught by QUnit itself, which stops the test execution with a failure.
Is there a way to tell QUnit that I want to handle errors on my own, or to manually throw errors so that my own window.onerror will be invoked instead of QUnit's?