Skip to content

Commit 7c2af7e

Browse files
committed
Core: Link to async hook example from async module callback error
Add link to the new example added in 086a0db from the new error message introduced in qunitjs#1761 (bad99f9), and rephrase the error message slightly to sound more like some of our other error messages. * TypeError instead of Error. * mention "QUnit.module() callback" explicitly.
1 parent 086a0db commit 7c2af7e

File tree

5 files changed

+10
-14
lines changed

5 files changed

+10
-14
lines changed

src/module.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ function processModule (name, options, executeNow, modifiers = {}) {
8989
}
9090

9191
if (isAsyncFunction(executeNow)) {
92-
throw new Error('Async module callbacks are not supported. ' +
93-
'Instead, use hooks for async behavior.');
92+
throw new TypeError('QUnit.module() callback must not be async. For async module setup, use hooks. https://qunitjs.com/api/QUnit/module/#hooks');
9493
}
9594

9695
const module = createModule(name, options, modifiers);
@@ -120,10 +119,7 @@ function processModule (name, options, executeNow, modifiers = {}) {
120119
try {
121120
const cbReturnValue = executeNow.call(module.testEnvironment, moduleFns);
122121
if (cbReturnValue && typeof cbReturnValue.then === 'function') {
123-
throw new Error(
124-
'Returning a promise from a module callback is not supported. ' +
125-
'Instead, use hooks for async behavior.'
126-
);
122+
throw new TypeError('QUnit.module() callback must not be async. For async module setup, use hooks. https://qunitjs.com/api/QUnit/module/#hooks');
127123
}
128124
} finally {
129125
// If the module closure threw an uncaught error during the load phase,

test/cli/fixtures/async-module-error-promise.tap.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ not ok 1 global failure
55
---
66
message: |+
77
Error: Failed to load file async-module-error-promise.js
8-
Error: Returning a promise from a module callback is not supported. Instead, use hooks for async behavior.
8+
TypeError: QUnit.module() callback must not be async. For async module setup, use hooks. https://qunitjs.com/api/QUnit/module/#hooks
99
severity: failed
1010
stack: |
11-
Error: Returning a promise from a module callback is not supported. Instead, use hooks for async behavior.
11+
TypeError: QUnit.module() callback must not be async. For async module setup, use hooks. https://qunitjs.com/api/QUnit/module/#hooks
1212
at qunit.js
1313
at /qunit/test/cli/fixtures/async-module-error-promise.js:1:7
1414
at internal

test/cli/fixtures/async-module-error-thenable.tap.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ not ok 1 global failure
55
---
66
message: |+
77
Error: Failed to load file async-module-error-thenable.js
8-
Error: Returning a promise from a module callback is not supported. Instead, use hooks for async behavior.
8+
TypeError: QUnit.module() callback must not be async. For async module setup, use hooks. https://qunitjs.com/api/QUnit/module/#hooks
99
severity: failed
1010
stack: |
11-
Error: Returning a promise from a module callback is not supported. Instead, use hooks for async behavior.
11+
TypeError: QUnit.module() callback must not be async. For async module setup, use hooks. https://qunitjs.com/api/QUnit/module/#hooks
1212
at qunit.js
1313
at /qunit/test/cli/fixtures/async-module-error-thenable.js:1:7
1414
at internal

test/cli/fixtures/async-module-error.tap.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ not ok 1 global failure
55
---
66
message: |+
77
Error: Failed to load file async-module-error.js
8-
Error: Async module callbacks are not supported. Instead, use hooks for async behavior.
8+
TypeError: QUnit.module() callback must not be async. For async module setup, use hooks. https://qunitjs.com/api/QUnit/module/#hooks
99
severity: failed
1010
stack: |
11-
Error: Async module callbacks are not supported. Instead, use hooks for async behavior.
11+
TypeError: QUnit.module() callback must not be async. For async module setup, use hooks. https://qunitjs.com/api/QUnit/module/#hooks
1212
at qunit.js
1313
at /qunit/test/cli/fixtures/async-module-error.js:2:7
1414
at internal

test/main/modules.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,8 @@ QUnit.module('QUnit.module', function () {
466466
}
467467

468468
QUnit.test('thenable callback function errored', function (assert) {
469-
assert.true(caught instanceof Error);
470-
assert.strictEqual(caught.message, 'Returning a promise from a module callback is not supported. Instead, use hooks for async behavior.');
469+
assert.true(caught instanceof TypeError);
470+
assert.strictEqual(caught.message, 'QUnit.module() callback must not be async. For async module setup, use hooks. https://qunitjs.com/api/QUnit/module/#hooks');
471471
});
472472
});
473473
});

0 commit comments

Comments
 (0)