diff --git a/docs/api/callbacks/QUnit.on.md b/docs/api/callbacks/QUnit.on.md index 027613d6c..8298aa13b 100644 --- a/docs/api/callbacks/QUnit.on.md +++ b/docs/api/callbacks/QUnit.on.md @@ -33,6 +33,7 @@ QUnit.on('runStart', runStart => { console.log(`Test plan: ${runStart.testCounts.total}`); }); ``` + ## The `suiteStart` event The `suiteStart` event indicates the beginning of a module. It is eventually be followed by a corresponding `suiteEnd` event. @@ -149,3 +150,19 @@ QUnit.on('runEnd', runEnd => { console.log(`Total: ${runEnd.total}`); }); ``` + +## The `error` event + +*Version added: [QUnit 2.17.0](https://github.com/qunitjs/qunit/releases/tag/2.17.0)*. + +The `error` event notifies plugins of uncaught global errors during a test run. + +See also [QUnit.onUncaughtException()](../extension/QUnit.onUncaughtException.md) which is where you can report your own uncaught errors. + +| `Error|any` | `error` + +```js +QUnit.on('error', error => { + console.error(error); +}); +``` diff --git a/docs/api/extension/QUnit.onUncaughtException.md b/docs/api/extension/QUnit.onUncaughtException.md index d1e5feaa8..e600b2758 100644 --- a/docs/api/extension/QUnit.onUncaughtException.md +++ b/docs/api/extension/QUnit.onUncaughtException.md @@ -28,6 +28,10 @@ In general, you should not use this method and instead throw an error. QUnit aut * QUnit CLI: `process.on('unhandledRejection', …)` * QUnit CLI: `process.on('uncaughtException', …)` +When QUnit receives report of a global error strictly inside a test (or one of its module hooks), the exception is reported to the currently running test as extra failed assertion, and thus the test will be marked as failed. This means that uncaught exceptions (such as calling an undefined function) during [QUnit.test.todo](../QUnit/test.todo.md) callback count as expected failure and **not** fail the test run. + +Errors received before tests (e.g. early event callbacks), internally between tests, or around the [runEnd event](../callbacks/QUnit.on.md#the-runend-event) (if the process is still alive for some reason), are emitted as an ["error" event](../callbacks/QUnit.on.md#the-error-event) to reporters. + ## Examples ```js