@@ -105,11 +105,11 @@ top level test with two subtests.
105
105
106
106
``` js
107
107
test (' top level test' , async (t ) => {
108
- await t .test (' subtest 1' , (t ) => {
108
+ t .test (' subtest 1' , (t ) => {
109
109
assert .strictEqual (1 , 1 );
110
110
});
111
111
112
- await t .test (' subtest 2' , (t ) => {
112
+ t .test (' subtest 2' , (t ) => {
113
113
assert .strictEqual (2 , 2 );
114
114
});
115
115
});
@@ -118,12 +118,7 @@ test('top level test', async (t) => {
118
118
> ** Note:** ` beforeEach ` and ` afterEach ` hooks are triggered
119
119
> between each subtest execution.
120
120
121
- In this example, ` await ` is used to ensure that both subtests have completed.
122
- This is necessary because tests do not wait for their subtests to
123
- complete, unlike tests created within suites.
124
- Any subtests that are still outstanding when their parent finishes
125
- are cancelled and treated as failures. Any subtest failures cause the parent
126
- test to fail.
121
+ Any subtest failures cause the parent test to fail.
127
122
128
123
## Skipping tests
129
124
@@ -241,20 +236,20 @@ that are not executed are omitted from the test runner output.
241
236
// The suite's 'only' option is set, so these tests are run.
242
237
test (' this test is run' , { only: true }, async (t ) => {
243
238
// Within this test, all subtests are run by default.
244
- await t .test (' running subtest' );
239
+ t .test (' running subtest' );
245
240
246
241
// The test context can be updated to run subtests with the 'only' option.
247
242
t .runOnly (true );
248
- await t .test (' this subtest is now skipped' );
249
- await t .test (' this subtest is run' , { only: true });
243
+ t .test (' this subtest is now skipped' );
244
+ t .test (' this subtest is run' , { only: true });
250
245
251
246
// Switch the context back to execute all tests.
252
247
t .runOnly (false );
253
- await t .test (' this subtest is now run' );
248
+ t .test (' this subtest is now run' );
254
249
255
250
// Explicitly do not run these tests.
256
- await t .test (' skipped subtest 3' , { only: false });
257
- await t .test (' skipped subtest 4' , { skip: true });
251
+ t .test (' skipped subtest 3' , { only: false });
252
+ t .test (' skipped subtest 4' , { skip: true });
258
253
});
259
254
260
255
// The 'only' option is not set, so this test is skipped.
@@ -309,13 +304,13 @@ multiple times (e.g. `--test-name-pattern="test 1"`,
309
304
310
305
``` js
311
306
test (' test 1' , async (t ) => {
312
- await t .test (' test 2' );
313
- await t .test (' test 3' );
307
+ t .test (' test 2' );
308
+ t .test (' test 3' );
314
309
});
315
310
316
311
test (' Test 4' , async (t ) => {
317
- await t .test (' Test 5' );
318
- await t .test (' test 6' );
312
+ t .test (' Test 5' );
313
+ t .test (' test 6' );
319
314
});
320
315
```
321
316
@@ -3175,12 +3170,9 @@ before each subtest of the current test.
3175
3170
``` js
3176
3171
test (' top level test' , async (t ) => {
3177
3172
t .beforeEach ((t ) => t .diagnostic (` about to run ${ t .name } ` ));
3178
- await t .test (
3179
- ' This is a subtest' ,
3180
- (t ) => {
3181
- assert .ok (' some relevant assertion here' );
3182
- },
3183
- );
3173
+ t .test (' This is a subtest' , (t ) => {
3174
+ assert .ok (' some relevant assertion here' );
3175
+ });
3184
3176
});
3185
3177
```
3186
3178
@@ -3238,12 +3230,9 @@ after each subtest of the current test.
3238
3230
``` js
3239
3231
test (' top level test' , async (t ) => {
3240
3232
t .afterEach ((t ) => t .diagnostic (` finished running ${ t .name } ` ));
3241
- await t .test (
3242
- ' This is a subtest' ,
3243
- (t ) => {
3244
- assert .ok (' some relevant assertion here' );
3245
- },
3246
- );
3233
+ t .test (' This is a subtest' , (t ) => {
3234
+ assert .ok (' some relevant assertion here' );
3235
+ });
3247
3236
});
3248
3237
```
3249
3238
@@ -3533,6 +3522,10 @@ added:
3533
3522
- v18.0.0
3534
3523
- v16.17.0
3535
3524
changes:
3525
+ - version:
3526
+ - REPLACEME
3527
+ pr-url: https://github.com/nodejs/node/pull/56664
3528
+ description: This function no longer returns a `Promise`.
3536
3529
- version:
3537
3530
- v18.8.0
3538
3531
- v16.18.0
@@ -3577,14 +3570,13 @@ changes:
3577
3570
to this function is a [ ` TestContext ` ] [ ] object. If the test uses callbacks,
3578
3571
the callback function is passed as the second argument. ** Default:** A no-op
3579
3572
function.
3580
- * Returns: {Promise} Fulfilled with ` undefined ` once the test completes.
3581
3573
3582
3574
This function is used to create subtests under the current test. This function
3583
3575
behaves in the same fashion as the top level [ ` test() ` ] [ ] function.
3584
3576
3585
3577
``` js
3586
3578
test (' top level test' , async (t ) => {
3587
- await t .test (
3579
+ t .test (
3588
3580
' This is a subtest' ,
3589
3581
{ only: false , skip: false , concurrency: 1 , todo: false , plan: 1 },
3590
3582
(t ) => {
0 commit comments