Skip to content

Commit

Permalink
Docs: Designate E0001 to "Unexpected test after runEnd" with examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Krinkle committed Jun 8, 2024
1 parent 6e0ead2 commit 99a8768
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions docs/api/config/autostart.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,22 @@ In the browser, QUnit by default waits for all `<script>` elements to finish lo

Set this property to `false` to instruct QUnit to wait longer, allowing you to load test files asynchronously. Remember to call [`QUnit.start()`](../QUnit/start.md) once you're ready for tests to begin running.

If you asynchronously load test files _without_ disabling autostart, you may encounter this warning:
## Examples

<p class="note note--warning" markdown="1">**warning**: Unexpected test after runEnd.</p>
### Error: Unexpected test after runEnd {#E0001}

If tests are new tests defined after QUnit has finished its run, you may encounter this error:

```
Error: Unexpected test after runEnd.
```

If you load test files asynchronously, make sure to disable autostart and call [`QUnit.start()`](../QUnit/start.md) accordingly.

If you encounter this error unrelated to autostart, it might be that you're dynamically registering a new [QUnit.test](./test.md) from inside a hook or event callback towards the end of the test run, such as `hooks.after()` or `QUnit.done()`. It is recommended to define dynamic tests via [`QUnit.begin()`](../callbacks/QUnit.begin.md) instead. ([#1663](https://github.com/qunitjs/qunit/issues/1663))

To report global errors from a plugin or other integration layer, consider calling [QUnit.onUncaughtException()](../QUnit/onUncaughtException.md) instead.

## Examples

### ESM Dynamic imports

Expand Down
2 changes: 1 addition & 1 deletion src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default function Test (settings) {
// (Meaning the CI would pass despite the late-failing test).
// Ref https://github.com/qunitjs/qunit/issues/1377
if (config.pq.finished) {
throw new Error('Unexpected test after runEnd. To report errors, consider calling QUnit.onUncaughtException() instead.');
throw new Error('Unexpected test after runEnd. https://qunitjs.com/api/QUnit/module/#E0001');
}
if (!this.skip && typeof this.callback !== 'function') {
const method = this.todo ? 'QUnit.todo' : 'QUnit.test';
Expand Down

0 comments on commit 99a8768

Please sign in to comment.