You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/versioned_docs/version-29.0/GlobalAPI.md
+43-35
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ import TOCInline from '@theme/TOCInline';
19
19
20
20
Runs a function after all the tests in this file have completed. If the function returns a promise or is a generator, Jest waits for that promise to resolve before continuing.
21
21
22
-
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. _Note: The default timeout is 5 seconds._
22
+
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. The default timeout is 5 seconds.
23
23
24
24
This is often useful if you want to clean up some global setup state that is shared across tests.
25
25
@@ -59,7 +59,7 @@ If you want to run some cleanup after every test instead of after all tests, use
59
59
60
60
Runs a function after each one of the tests in this file completes. If the function returns a promise or is a generator, Jest waits for that promise to resolve before continuing.
61
61
62
-
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. _Note: The default timeout is 5 seconds._
62
+
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. The default timeout is 5 seconds.
63
63
64
64
This is often useful if you want to clean up some temporary state that is created by each test.
65
65
@@ -99,7 +99,7 @@ If you want to run some cleanup just once, after all of the tests run, use `afte
99
99
100
100
Runs a function before any of the tests in this file run. If the function returns a promise or is a generator, Jest waits for that promise to resolve before running tests.
101
101
102
-
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. _Note: The default timeout is 5 seconds._
102
+
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. The default timeout is 5 seconds.
103
103
104
104
This is often useful if you want to set up some global state that will be used by many tests.
105
105
@@ -135,7 +135,7 @@ If you want to run something before every test instead of before any test runs,
135
135
136
136
Runs a function before each of the tests in this file runs. If the function returns a promise or is a generator, Jest waits for that promise to resolve before running the test.
137
137
138
-
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. _Note: The default timeout is 5 seconds._
138
+
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. The default timeout is 5 seconds.
139
139
140
140
This is often useful if you want to reset some global state that will be used by many tests.
141
141
@@ -232,8 +232,8 @@ Use `describe.each` if you keep duplicating the same test suites with different
232
232
233
233
#### 1. `describe.each(table)(name, fn, timeout)`
234
234
235
-
-`table`: `Array` of Arrays with the arguments that are passed into the `fn` for each row.
236
-
-_Note_ If you pass in a 1D array of primitives, internally it will be mapped to a table i.e. `[1, 2, 3] -> [[1], [2], [3]]`
235
+
-`table`: `Array` of Arrays with the arguments that are passed into the `fn` for each row. If you pass in a 1D array of primitives, internally it will be mapped to a table i.e. `[1, 2, 3] -> [[1], [2], [3]]`.
236
+
237
237
-`name`: `String` the title of the test suite.
238
238
- Generate unique test titles by positionally injecting parameters with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
@@ -250,7 +250,7 @@ Use `describe.each` if you keep duplicating the same test suites with different
250
250
- You can use `$#` to inject the index of the test case
251
251
- You cannot use `$variable` with the `printf` formatting except for `%%`
252
252
-`fn`: `Function` the suite of tests to be ran, this is the function that will receive the parameters in each row as function arguments.
253
-
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. _Note: The default timeout is 5 seconds._
253
+
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. The default timeout is 5 seconds.
254
254
255
255
Example:
256
256
@@ -302,7 +302,7 @@ describe.each([
302
302
-`name`: `String` the title of the test suite, use `$variable` to inject test data into the suite title from the tagged template expressions, and `$#` for the index of the row.
303
303
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
304
304
-`fn`: `Function` the suite of tests to be ran, this is the function that will receive the test data object.
305
-
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. _Note: The default timeout is 5 seconds._
305
+
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. The default timeout is 5 seconds.
306
306
307
307
Example:
308
308
@@ -475,11 +475,9 @@ test('did not rain', () => {
475
475
});
476
476
```
477
477
478
-
The first argument is the test name; the second argument is a function that contains the expectations to test. The third argument (optional) is `timeout` (in milliseconds) for specifying how long to wait before aborting. _Note: The default timeout is 5 seconds._
479
-
480
-
> Note: If a **promise is returned** from `test`, Jest will wait for the promise to resolve before letting the test complete. Jest will also wait if you **provide an argument to the test function**, usually called `done`. This could be handy when you want to test callbacks. See how to test async code [here](TestingAsyncCode.md#callbacks).
478
+
The first argument is the test name; the second argument is a function that contains the expectations to test. The third argument (optional) is `timeout` (in milliseconds) for specifying how long to wait before aborting. The default timeout is 5 seconds.
481
479
482
-
For example, let's say `fetchBeverageList()` returns a promise that is supposed to resolve to a list that has `lemon` in it. You can test this with:
480
+
If a **promise is returned** from `test`, Jest will wait for the promise to resolve before letting the test complete. For example, let's say `fetchBeverageList()` returns a promise that is supposed to resolve to a list that has `lemon` in it. You can test this with:
Even though the call to `test` will return right away, the test doesn't complete until the promise resolves as well.
490
+
Even though the call to `test` will return right away, the test doesn't complete until the promise resolves. For more details, see [Testing Asynchronous Code](TestingAsyncCode.md) page.
491
+
492
+
:::tip
493
+
494
+
Jest will also wait if you **provide an argument to the test function**, usually called `done`. This could be handy when you want to test [callbacks](TestingAsyncCode.md#callbacks).
495
+
496
+
:::
493
497
494
498
### `test.concurrent(name, fn, timeout)`
495
499
496
500
Also under the alias: `it.concurrent(name, fn, timeout)`
497
501
498
-
Use `test.concurrent` if you want the test to run concurrently.
502
+
:::caution
499
503
500
-
> Note: `test.concurrent` is considered experimental - see [here](https://github.com/facebook/jest/labels/Area%3A%20Concurrent) for details on missing features and other issues
504
+
`test.concurrent` is considered experimental - see [here](https://github.com/facebook/jest/labels/Area%3A%20Concurrent) for details on missing features and other issues.
501
505
502
-
The first argument is the test name; the second argument is an asynchronous function that contains the expectations to test. The third argument (optional) is `timeout` (in milliseconds) for specifying how long to wait before aborting. _Note: The default timeout is 5 seconds._
506
+
:::
503
507
504
-
```
508
+
Use `test.concurrent` if you want the test to run concurrently.
509
+
510
+
The first argument is the test name; the second argument is an asynchronous function that contains the expectations to test. The third argument (optional) is `timeout` (in milliseconds) for specifying how long to wait before aborting. The default timeout is 5 seconds.
511
+
512
+
```js
505
513
test.concurrent('addition of 2 numbers', async () => {
> Note: Use `maxConcurrency` in configuration to prevents Jest from executing more than the specified amount of tests at the same time
522
+
:::tip
523
+
524
+
Use [`maxConcurrency`](Configuration.md/#maxconcurrency-number) configuration option to prevent Jest from executing more than the specified amount of tests at the same time.
-`table`: `Array` of Arrays with the arguments that are passed into the test `fn` for each row.
527
-
-_Note_ If you pass in a 1D array of primitives, internally it will be mapped to a table i.e. `[1, 2, 3] -> [[1], [2], [3]]`
538
+
-`table`: `Array` of Arrays with the arguments that are passed into the test `fn` for each row. If you pass in a 1D array of primitives, internally it will be mapped to a table i.e. `[1, 2, 3] -> [[1], [2], [3]]`
528
539
-`name`: `String` the title of the test block.
529
540
- Generate unique test titles by positionally injecting parameters with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
@@ -537,7 +548,7 @@ Use `test.concurrent.each` if you keep duplicating the same test with different
537
548
-`%#` - Index of the test case.
538
549
-`%%` - single percent sign ('%'). This does not consume an argument.
539
550
-`fn`: `Function` the test to be ran, this is the function that will receive the parameters in each row as function arguments, **this will have to be an asynchronous function**.
540
-
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. _Note: The default timeout is 5 seconds._
551
+
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. The default timeout is 5 seconds.
541
552
542
553
Example:
543
554
@@ -559,7 +570,7 @@ test.concurrent.each([
559
570
-`name`: `String` the title of the test, use `$variable` to inject test data into the test title from the tagged template expressions.
560
571
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
561
572
-`fn`: `Function` the test to be ran, this is the function that will receive the test data object, **this will have to be an asynchronous function**.
562
-
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. _Note: The default timeout is 5 seconds._
573
+
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. The default timeout is 5 seconds.
563
574
564
575
Example:
565
576
@@ -666,8 +677,7 @@ Use `test.each` if you keep duplicating the same test with different data. `test
666
677
667
678
#### 1. `test.each(table)(name, fn, timeout)`
668
679
669
-
-`table`: `Array` of Arrays with the arguments that are passed into the test `fn` for each row.
670
-
-_Note_ If you pass in a 1D array of primitives, internally it will be mapped to a table i.e. `[1, 2, 3] -> [[1], [2], [3]]`
680
+
-`table`: `Array` of Arrays with the arguments that are passed into the test `fn` for each row. If you pass in a 1D array of primitives, internally it will be mapped to a table i.e. `[1, 2, 3] -> [[1], [2], [3]]`
671
681
-`name`: `String` the title of the test block.
672
682
- Generate unique test titles by positionally injecting parameters with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
@@ -684,7 +694,7 @@ Use `test.each` if you keep duplicating the same test with different data. `test
684
694
- You can use `$#` to inject the index of the test case
685
695
- You cannot use `$variable` with the `printf` formatting except for `%%`
686
696
-`fn`: `Function` the test to be ran, this is the function that will receive the parameters in each row as function arguments.
687
-
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. _Note: The default timeout is 5 seconds._
697
+
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. The default timeout is 5 seconds.
688
698
689
699
Example:
690
700
@@ -716,7 +726,7 @@ test.each([
716
726
-`name`: `String` the title of the test, use `$variable` to inject test data into the test title from the tagged template expressions.
717
727
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
718
728
-`fn`: `Function` the test to be ran, this is the function that will receive the test data object.
719
-
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. _Note: The default timeout is 5 seconds._
729
+
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. The default timeout is 5 seconds.
720
730
721
731
Example:
722
732
@@ -817,7 +827,7 @@ Also under the aliases: `it.only(name, fn, timeout)`, and `fit(name, fn, timeout
817
827
818
828
When you are debugging a large test file, you will often only want to run a subset of tests. You can use `.only` to specify which tests are the only ones you want to run in that test file.
819
829
820
-
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. _Note: The default timeout is 5 seconds._
830
+
Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait before aborting. The default timeout is 5 seconds.
821
831
822
832
For example, let's say you had these tests:
823
833
@@ -945,20 +955,18 @@ Also under the alias: `it.todo(name)`
945
955
946
956
Use `test.todo` when you are planning on writing tests. These tests will be highlighted in the summary output at the end so you know how many tests you still need todo.
947
957
948
-
_Note_: If you supply a test callback function then the `test.todo` will throw an error. If you have already implemented the test and it is broken and you do not want it to run, then use `test.skip` instead.
949
-
950
-
#### API
951
-
952
-
-`name`: `String` the title of the test plan.
953
-
954
-
Example:
955
-
956
958
```js
957
959
constadd= (a, b) => a + b;
958
960
959
961
test.todo('add should be associative');
960
962
```
961
963
964
+
:::tip
965
+
966
+
`test.todo` will throw an error, if you will pass it a test callback function. Use [`test.skip`](#testskipname-fn) instead, if you already implemented the test, but do not want it to run.
0 commit comments