@@ -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' ;
@@ -1204,6 +1203,51 @@ run({ files: [path.resolve('./tests/test.js')] })
1204
1203
.pipe (process .stdout );
1205
1204
```
1206
1205
1206
+ ## ` suite([name][, options][, fn]) `
1207
+
1208
+ <!-- YAML
1209
+ added: REPLACEME
1210
+ -->
1211
+
1212
+ * ` name ` {string} The name of the suite, which is displayed when reporting test
1213
+ results. ** Default:** The ` name ` property of ` fn ` , or ` '<anonymous>' ` if ` fn `
1214
+ does not have a name.
1215
+ * ` options ` {Object} Optional configuration options for the suite.
1216
+ This supports the same options as ` test([name][, options][, fn]) ` .
1217
+ * ` fn ` {Function|AsyncFunction} The suite function declaring nested tests and
1218
+ suites. The first argument to this function is a [ ` SuiteContext ` ] [ ] object.
1219
+ ** Default:** A no-op function.
1220
+ * Returns: {Promise} Immediately fulfilled with ` undefined ` .
1221
+
1222
+ The ` suite() ` function is imported from the ` node:test ` module.
1223
+
1224
+ ## ` suite.skip([name][, options][, fn]) `
1225
+
1226
+ <!-- YAML
1227
+ added: REPLACEME
1228
+ -->
1229
+
1230
+ Shorthand for skipping a suite. This is the same as
1231
+ [ ` suite([name], { skip: true }[, fn]) ` ] [ suite options ] .
1232
+
1233
+ ## ` suite.todo([name][, options][, fn]) `
1234
+
1235
+ <!-- YAML
1236
+ added: REPLACEME
1237
+ -->
1238
+
1239
+ Shorthand for marking a suite as ` TODO ` . This is the same as
1240
+ [ ` suite([name], { todo: true }[, fn]) ` ] [ suite options ] .
1241
+
1242
+ ## ` suite.only([name][, options][, fn]) `
1243
+
1244
+ <!-- YAML
1245
+ added: REPLACEME
1246
+ -->
1247
+
1248
+ Shorthand for marking a suite as ` only ` . This is the same as
1249
+ [ ` suite([name], { only: true }[, fn]) ` ] [ suite options ] .
1250
+
1207
1251
## ` test([name][, options][, fn]) `
1208
1252
1209
1253
<!-- YAML
@@ -1257,7 +1301,7 @@ changes:
1257
1301
the callback function is passed as the second argument. ** Default:** A no-op
1258
1302
function.
1259
1303
* Returns: {Promise} Fulfilled with ` undefined ` once
1260
- the test completes, or immediately if the test runs within [ ` describe() ` ] [ ] .
1304
+ the test completes, or immediately if the test runs within a suite .
1261
1305
1262
1306
The ` test() ` function is the value imported from the ` test ` module. Each
1263
1307
invocation of this function results in reporting the test to the {TestsStream}.
@@ -1267,7 +1311,7 @@ actions related to the current test. Examples include skipping the test, adding
1267
1311
additional diagnostic information, or creating subtests.
1268
1312
1269
1313
` test() ` returns a ` Promise ` that fulfills once the test completes.
1270
- if ` test() ` is called within a ` describe() ` block , it fulfills immediately.
1314
+ if ` test() ` is called within a suite , it fulfills immediately.
1271
1315
The return value can usually be discarded for top level tests.
1272
1316
However, the return value from subtests should be used to prevent the parent
1273
1317
test from finishing first and cancelling the subtest
@@ -1308,29 +1352,18 @@ same as [`test([name], { only: true }[, fn])`][it options].
1308
1352
1309
1353
## ` describe([name][, options][, fn]) `
1310
1354
1311
- * ` name ` {string} The name of the suite, which is displayed when reporting test
1312
- results. ** Default:** The ` name ` property of ` fn ` , or ` '<anonymous>' ` if ` fn `
1313
- does not have a name.
1314
- * ` options ` {Object} Configuration options for the suite.
1315
- supports the same options as ` test([name][, options][, fn]) ` .
1316
- * ` fn ` {Function|AsyncFunction} The function under suite
1317
- declaring all subtests and subsuites.
1318
- The first argument to this function is a [ ` SuiteContext ` ] [ ] object.
1319
- ** Default:** A no-op function.
1320
- * Returns: {Promise} Immediately fulfilled with ` undefined ` .
1355
+ Alias for [ ` suite() ` ] [ ] .
1321
1356
1322
- The ` describe() ` function imported from the ` node:test ` module. Each
1323
- invocation of this function results in the creation of a Subtest.
1324
- After invocation of top level ` describe ` functions,
1325
- all top level tests and suites will execute.
1357
+ The ` describe() ` function is imported from the ` node:test ` module.
1326
1358
1327
1359
## ` describe.skip([name][, options][, fn]) `
1328
1360
1329
- Shorthand for skipping a suite, same as [ ` describe([name], { skip: true }[, fn]) ` ] [ describe options ] .
1361
+ Shorthand for skipping a suite. This is the same as
1362
+ [ ` describe([name], { skip: true }[, fn]) ` ] [ describe options ] .
1330
1363
1331
1364
## ` describe.todo([name][, options][, fn]) `
1332
1365
1333
- Shorthand for marking a suite as ` TODO ` , same as
1366
+ Shorthand for marking a suite as ` TODO ` . This is the same as
1334
1367
[ ` describe([name], { todo: true }[, fn]) ` ] [ describe options ] .
1335
1368
1336
1369
## ` describe.only([name][, options][, fn]) `
@@ -1341,7 +1374,7 @@ added:
1341
1374
- v18.15.0
1342
1375
-->
1343
1376
1344
- Shorthand for marking a suite as ` only ` , same as
1377
+ Shorthand for marking a suite as ` only ` . This is the same as
1345
1378
[ ` describe([name], { only: true }[, fn]) ` ] [ describe options ] .
1346
1379
1347
1380
## ` it([name][, options][, fn]) `
@@ -1358,7 +1391,7 @@ changes:
1358
1391
description: Calling `it()` is now equivalent to calling `test()`.
1359
1392
-->
1360
1393
1361
- Shorthand for [ ` test() ` ] [ ] .
1394
+ Alias for [ ` test() ` ] [ ] .
1362
1395
1363
1396
The ` it() ` function is imported from the ` node:test ` module.
1364
1397
@@ -1402,7 +1435,7 @@ added:
1402
1435
If unspecified, subtests inherit this value from their parent.
1403
1436
** Default:** ` Infinity ` .
1404
1437
1405
- This function is used to create a hook running before running a suite.
1438
+ This function creates a hook that runs before executing a suite.
1406
1439
1407
1440
``` js
1408
1441
describe (' tests' , async () => {
@@ -1432,7 +1465,7 @@ added:
1432
1465
If unspecified, subtests inherit this value from their parent.
1433
1466
** Default:** ` Infinity ` .
1434
1467
1435
- This function is used to create a hook running after running a suite.
1468
+ This function creates a hook that runs after executing a suite.
1436
1469
1437
1470
``` js
1438
1471
describe (' tests' , async () => {
@@ -1465,8 +1498,7 @@ added:
1465
1498
If unspecified, subtests inherit this value from their parent.
1466
1499
** Default:** ` Infinity ` .
1467
1500
1468
- This function is used to create a hook running
1469
- before each subtest of the current suite.
1501
+ This function creates a hook that runs before each test in the current suite.
1470
1502
1471
1503
``` js
1472
1504
describe (' tests' , async () => {
@@ -1496,11 +1528,8 @@ added:
1496
1528
If unspecified, subtests inherit this value from their parent.
1497
1529
** Default:** ` Infinity ` .
1498
1530
1499
- This function is used to create a hook running
1500
- after each subtest of the current test.
1501
-
1502
- ** Note:** The ` afterEach ` hook is guaranteed to run after every test,
1503
- even if any of the tests fail.
1531
+ This function creates a hook that runs after each test in the current suite.
1532
+ The ` afterEach() ` hook is run even if the test fails.
1504
1533
1505
1534
``` js
1506
1535
describe (' tests' , async () => {
@@ -3075,10 +3104,13 @@ Can be used to abort test subtasks when the test has been aborted.
3075
3104
[ `context.todo` ] : #contexttodomessage
3076
3105
[ `describe()` ] : #describename-options-fn
3077
3106
[ `glob(7)` ] : https://man7.org/linux/man-pages/man7/glob.7.html
3107
+ [ `it()` ] : #itname-options-fn
3078
3108
[ `run()` ] : #runoptions
3109
+ [ `suite()` ] : #suitename-options-fn
3079
3110
[ `test()` ] : #testname-options-fn
3080
3111
[ describe options ] : #describename-options-fn
3081
3112
[ it options ] : #testname-options-fn
3082
3113
[ stream.compose ] : stream.md#streamcomposestreams
3114
+ [ suite options ] : #suitename-options-fn
3083
3115
[ test reporters ] : #test-reporters
3084
3116
[ test runner execution model ] : #test-runner-execution-model
0 commit comments