Skip to content

Commit

Permalink
Docs: Add docs for "error" event
Browse files Browse the repository at this point in the history
Ref #1638.
  • Loading branch information
Krinkle committed Jul 10, 2024
1 parent 45b6c0b commit c3d9fe8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/api/callbacks/QUnit.on.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
});
```
4 changes: 4 additions & 0 deletions docs/api/extension/QUnit.onUncaughtException.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c3d9fe8

Please sign in to comment.