If one were to delve into the qUnit source code, they would discover two different methods for handling exceptions. The first method is controlled by the config.notrycatch
setting and involves wrapping test setup, execution, and teardown in try..catch
blocks. While this approach may not effectively handle exceptions thrown by asynchronous tests since qUnit is not the caller in those scenarios, there exists an additional mechanism known as the window.onerror
handler which is governed by the Test.ignoreGlobalErrors
setting. By default, both settings are set to false
, ensuring that both types of exceptions are caught successfully.
test("foo", function() {
stop();
function myfun(ed) {
start();
ok(1, 'entered qunit again');
throw "bar";
}
setTimeout(myfun, 1000);
});
Running the above code (excluding TinyMCE-specific parts) yields expected results with a passed test message followed by a failed one indicating an uncaught exception. If this methodology does not work in a specific case, several possibilities could be considered:
- The version of qUnit being used predates the resolution of qUnit issue 134 where a global exception handler was added.
- The
Test.ignoreGlobalErrors
setting is being altered within the codebase (unlikely).
- An existing
window.onerror
handler returns true
, thus indicating to qUnit that the error has been handled. It seems unlikely that TinyMCE includes such a handler by default.
- TinyMCE may catch errors in event handlers when executed, a common practice to ensure continued callback execution even if exceptions occur.
Update: Another possibility overlooked previously is that the exception occurs within a frame where qUnit has not established its global error handler. Implementing the following code snippet in the frame should rectify this issue:
window.onerror = function() {
if (parent.onerror) {
return parent.onerror.apply(parent, arguments);
} else
return false;
}
In regards to your side note: the order in which messages appear using the console
object is not guaranteed. The example console.log("foo");throw "bar";
demonstrates that exceptions are displayed before log messages, suggesting that log messages are processed asynchronously for potential performance optimizations. For precise details on how the console
object operates in Firefox, examining the implementation specifics would be necessary.