@@ -128,8 +128,8 @@ test('top level test', async (t) => {
128
128
> between each subtest execution.
129
129
130
130
In this example, ` await ` is used to ensure that both subtests have completed.
131
- This is necessary because parent tests do not wait for their subtests to
132
- complete, unlike tests created with the ` describe ` and ` it ` syntax .
131
+ This is necessary because tests do not wait for their subtests to
132
+ complete, unlike tests created within suites .
133
133
Any subtests that are still outstanding when their parent finishes
134
134
are cancelled and treated as failures. Any subtest failures cause the parent
135
135
test to fail.
@@ -162,12 +162,11 @@ test('skip() method with message', (t) => {
162
162
});
163
163
```
164
164
165
- ## ` describe ` / ` it ` syntax
165
+ ## ` describe() ` and ` it() ` aliases
166
166
167
- Running tests can also be done using ` describe ` to declare a suite
168
- and ` it ` to declare a test.
169
- A suite is used to organize and group related tests together.
170
- ` it ` is a shorthand for [ ` test() ` ] [ ] .
167
+ Suites and tests can also be written using the ` describe() ` and ` it() `
168
+ functions. [ ` describe() ` ] [ ] is an alias for [ ` suite() ` ] [ ] , and [ ` it() ` ] [ ] is an
169
+ alias for [ ` test() ` ] [ ] .
171
170
172
171
``` js
173
172
describe (' A thing' , () => {
@@ -187,7 +186,7 @@ describe('A thing', () => {
187
186
});
188
187
```
189
188
190
- ` describe ` and ` it ` are imported from the ` node:test ` module.
189
+ ` describe() ` and ` it() ` are imported from the ` node:test ` module.
191
190
192
191
``` mjs
193
192
import { describe , it } from ' node:test' ;
@@ -1200,6 +1199,51 @@ run({ files: [path.resolve('./tests/test.js')] })
1200
1199
.pipe (process .stdout );
1201
1200
```
1202
1201
1202
+ ## ` suite([name][, options][, fn]) `
1203
+
1204
+ <!-- YAML
1205
+ added: REPLACEME
1206
+ -->
1207
+
1208
+ * ` name ` {string} The name of the suite, which is displayed when reporting test
1209
+ results. ** Default:** The ` name ` property of ` fn ` , or ` '<anonymous>' ` if ` fn `
1210
+ does not have a name.
1211
+ * ` options ` {Object} Optional configuration options for the suite.
1212
+ This supports the same options as ` test([name][, options][, fn]) ` .
1213
+ * ` fn ` {Function|AsyncFunction} The suite function declaring nested tests and
1214
+ suites. The first argument to this function is a [ ` SuiteContext ` ] [ ] object.
1215
+ ** Default:** A no-op function.
1216
+ * Returns: {Promise} Immediately fulfilled with ` undefined ` .
1217
+
1218
+ The ` suite() ` function is imported from the ` node:test ` module.
1219
+
1220
+ ## ` suite.skip([name][, options][, fn]) `
1221
+
1222
+ <!-- YAML
1223
+ added: REPLACEME
1224
+ -->
1225
+
1226
+ Shorthand for skipping a suite. This is the same as
1227
+ [ ` suite([name], { skip: true }[, fn]) ` ] [ suite options ] .
1228
+
1229
+ ## ` suite.todo([name][, options][, fn]) `
1230
+
1231
+ <!-- YAML
1232
+ added: REPLACEME
1233
+ -->
1234
+
1235
+ Shorthand for marking a suite as ` TODO ` . This is the same as
1236
+ [ ` suite([name], { todo: true }[, fn]) ` ] [ suite options ] .
1237
+
1238
+ ## ` suite.only([name][, options][, fn]) `
1239
+
1240
+ <!-- YAML
1241
+ added: REPLACEME
1242
+ -->
1243
+
1244
+ Shorthand for marking a suite as ` only ` . This is the same as
1245
+ [ ` suite([name], { only: true }[, fn]) ` ] [ suite options ] .
1246
+
1203
1247
## ` test([name][, options][, fn]) `
1204
1248
1205
1249
<!-- YAML
@@ -1251,7 +1295,7 @@ changes:
1251
1295
the callback function is passed as the second argument. ** Default:** A no-op
1252
1296
function.
1253
1297
* Returns: {Promise} Fulfilled with ` undefined ` once
1254
- the test completes, or immediately if the test runs within [ ` describe() ` ] [ ] .
1298
+ the test completes, or immediately if the test runs within a suite .
1255
1299
1256
1300
The ` test() ` function is the value imported from the ` test ` module. Each
1257
1301
invocation of this function results in reporting the test to the {TestsStream}.
@@ -1261,7 +1305,7 @@ actions related to the current test. Examples include skipping the test, adding
1261
1305
additional diagnostic information, or creating subtests.
1262
1306
1263
1307
` test() ` returns a ` Promise ` that fulfills once the test completes.
1264
- if ` test() ` is called within a ` describe() ` block , it fulfills immediately.
1308
+ if ` test() ` is called within a suite , it fulfills immediately.
1265
1309
The return value can usually be discarded for top level tests.
1266
1310
However, the return value from subtests should be used to prevent the parent
1267
1311
test from finishing first and cancelling the subtest
@@ -1302,29 +1346,18 @@ same as [`test([name], { only: true }[, fn])`][it options].
1302
1346
1303
1347
## ` describe([name][, options][, fn]) `
1304
1348
1305
- * ` name ` {string} The name of the suite, which is displayed when reporting test
1306
- results. ** Default:** The ` name ` property of ` fn ` , or ` '<anonymous>' ` if ` fn `
1307
- does not have a name.
1308
- * ` options ` {Object} Configuration options for the suite.
1309
- supports the same options as ` test([name][, options][, fn]) ` .
1310
- * ` fn ` {Function|AsyncFunction} The function under suite
1311
- declaring all subtests and subsuites.
1312
- The first argument to this function is a [ ` SuiteContext ` ] [ ] object.
1313
- ** Default:** A no-op function.
1314
- * Returns: {Promise} Immediately fulfilled with ` undefined ` .
1349
+ Alias for [ ` suite() ` ] [ ] .
1315
1350
1316
- The ` describe() ` function imported from the ` node:test ` module. Each
1317
- invocation of this function results in the creation of a Subtest.
1318
- After invocation of top level ` describe ` functions,
1319
- all top level tests and suites will execute.
1351
+ The ` describe() ` function is imported from the ` node:test ` module.
1320
1352
1321
1353
## ` describe.skip([name][, options][, fn]) `
1322
1354
1323
- Shorthand for skipping a suite, same as [ ` describe([name], { skip: true }[, fn]) ` ] [ describe options ] .
1355
+ Shorthand for skipping a suite. This is the same as
1356
+ [ ` describe([name], { skip: true }[, fn]) ` ] [ describe options ] .
1324
1357
1325
1358
## ` describe.todo([name][, options][, fn]) `
1326
1359
1327
- Shorthand for marking a suite as ` TODO ` , same as
1360
+ Shorthand for marking a suite as ` TODO ` . This is the same as
1328
1361
[ ` describe([name], { todo: true }[, fn]) ` ] [ describe options ] .
1329
1362
1330
1363
## ` describe.only([name][, options][, fn]) `
@@ -1335,7 +1368,7 @@ added:
1335
1368
- v18.15.0
1336
1369
-->
1337
1370
1338
- Shorthand for marking a suite as ` only ` , same as
1371
+ Shorthand for marking a suite as ` only ` . This is the same as
1339
1372
[ ` describe([name], { only: true }[, fn]) ` ] [ describe options ] .
1340
1373
1341
1374
## ` it([name][, options][, fn]) `
@@ -1350,7 +1383,7 @@ changes:
1350
1383
description: Calling `it()` is now equivalent to calling `test()`.
1351
1384
-->
1352
1385
1353
- Shorthand for [ ` test() ` ] [ ] .
1386
+ Alias for [ ` test() ` ] [ ] .
1354
1387
1355
1388
The ` it() ` function is imported from the ` node:test ` module.
1356
1389
@@ -1394,7 +1427,7 @@ added:
1394
1427
If unspecified, subtests inherit this value from their parent.
1395
1428
** Default:** ` Infinity ` .
1396
1429
1397
- This function is used to create a hook running before running a suite.
1430
+ This function creates a hook that runs before executing a suite.
1398
1431
1399
1432
``` js
1400
1433
describe (' tests' , async () => {
@@ -1424,7 +1457,7 @@ added:
1424
1457
If unspecified, subtests inherit this value from their parent.
1425
1458
** Default:** ` Infinity ` .
1426
1459
1427
- This function is used to create a hook running after running a suite.
1460
+ This function creates a hook that runs after executing a suite.
1428
1461
1429
1462
``` js
1430
1463
describe (' tests' , async () => {
@@ -1457,8 +1490,7 @@ added:
1457
1490
If unspecified, subtests inherit this value from their parent.
1458
1491
** Default:** ` Infinity ` .
1459
1492
1460
- This function is used to create a hook running
1461
- before each subtest of the current suite.
1493
+ This function creates a hook that runs before each test in the current suite.
1462
1494
1463
1495
``` js
1464
1496
describe (' tests' , async () => {
@@ -1488,11 +1520,8 @@ added:
1488
1520
If unspecified, subtests inherit this value from their parent.
1489
1521
** Default:** ` Infinity ` .
1490
1522
1491
- This function is used to create a hook running
1492
- after each subtest of the current test.
1493
-
1494
- ** Note:** The ` afterEach ` hook is guaranteed to run after every test,
1495
- even if any of the tests fail.
1523
+ This function creates a hook that runs after each test in the current suite.
1524
+ The ` afterEach() ` hook is run even if the test fails.
1496
1525
1497
1526
``` js
1498
1527
describe (' tests' , async () => {
@@ -3054,10 +3083,13 @@ Can be used to abort test subtasks when the test has been aborted.
3054
3083
[ `context.skip` ] : #contextskipmessage
3055
3084
[ `context.todo` ] : #contexttodomessage
3056
3085
[ `describe()` ] : #describename-options-fn
3086
+ [ `it()` ] : #itname-options-fn
3057
3087
[ `run()` ] : #runoptions
3088
+ [ `suite()` ] : #suitename-options-fn
3058
3089
[ `test()` ] : #testname-options-fn
3059
3090
[ describe options ] : #describename-options-fn
3060
3091
[ it options ] : #testname-options-fn
3061
3092
[ stream.compose ] : stream.md#streamcomposestreams
3093
+ [ suite options ] : #suitename-options-fn
3062
3094
[ test reporters ] : #test-reporters
3063
3095
[ test runner execution model ] : #test-runner-execution-model
0 commit comments