@@ -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
@@ -3458,10 +3447,8 @@ no-op.
3458
3447
test (' top level test' , (t ) => {
3459
3448
// The test context can be set to run subtests with the 'only' option.
3460
3449
t .runOnly (true );
3461
- return Promise .all ([
3462
- t .test (' this subtest is now skipped' ),
3463
- t .test (' this subtest is run' , { only: true }),
3464
- ]);
3450
+ t .test (' this subtest is now skipped' );
3451
+ t .test (' this subtest is run' , { only: true });
3465
3452
});
3466
3453
```
3467
3454
@@ -3533,6 +3520,10 @@ added:
3533
3520
- v18.0.0
3534
3521
- v16.17.0
3535
3522
changes:
3523
+ - version:
3524
+ - REPLACEME
3525
+ pr-url: https://github.com/nodejs/node/pull/56664
3526
+ description: This function no longer returns a `Promise`.
3536
3527
- version:
3537
3528
- v18.8.0
3538
3529
- v16.18.0
@@ -3577,14 +3568,13 @@ changes:
3577
3568
to this function is a [ ` TestContext ` ] [ ] object. If the test uses callbacks,
3578
3569
the callback function is passed as the second argument. ** Default:** A no-op
3579
3570
function.
3580
- * Returns: {Promise} Fulfilled with ` undefined ` once the test completes.
3581
3571
3582
3572
This function is used to create subtests under the current test. This function
3583
3573
behaves in the same fashion as the top level [ ` test() ` ] [ ] function.
3584
3574
3585
3575
``` js
3586
3576
test (' top level test' , async (t ) => {
3587
- await t .test (
3577
+ t .test (
3588
3578
' This is a subtest' ,
3589
3579
{ only: false , skip: false , concurrency: 1 , todo: false , plan: 1 },
3590
3580
(t ) => {
0 commit comments