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: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,7 @@
3
3
### Features
4
4
5
5
-`[jest-circus, jest-jasmine2]` Include `failureDetails` property in test results ([#9496](https://github.com/facebook/jest/pull/9496))
6
+
-`[jest-each, jest-jasmine, jest-circus]` Add support for .concurrent.each ([#9326](https://github.com/facebook/jest/pull/9326))
Even though the call to `test` will return right away, the test doesn't complete until the promise resolves as well.
467
467
468
+
### `test.concurrent(name, fn, timeout)`
469
+
470
+
Also under the alias: `it.concurrent(name, fn, timeout)`
471
+
472
+
Use `test.concurrent` if you want the test to run concurrently.
473
+
474
+
> 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
475
+
476
+
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._
477
+
478
+
```
479
+
test.concurrent('addition of 2 numbers', async () => {
Also under the alias: `it.concurrent.each(table)(name, fn, timeout)`
493
+
494
+
Use `test.concurrent.each` if you keep duplicating the same test with different data. `test.each` allows you to write the test once and pass data in, the tests are all run asynchronously.
495
+
496
+
`test.concurrent.each` is available with two APIs:
-`table`: `Array` of Arrays with the arguments that are passed into the test `fn` for each row.
501
+
-_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]]`
502
+
-`name`: `String` the title of the test block.
503
+
- Generate unique test titles by positionally injecting parameters with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
-`%%` - single percent sign ('%'). This does not consume an argument.
513
+
-`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**.
514
+
- 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._
- First row of variable name column headings separated with `|`
532
+
- One or more subsequent rows of data supplied as template literal expressions using `${value}` syntax.
533
+
-`name`: `String` the title of the test, use `$variable` to inject test data into the test title from the tagged template expressions.
534
+
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
535
+
-`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**.
536
+
- 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._
537
+
538
+
Example:
539
+
540
+
```js
541
+
test.concurrent.each`
542
+
a | b | expected
543
+
${1} | ${1} | ${2}
544
+
${1} | ${2} | ${3}
545
+
${2} | ${1} | ${3}
546
+
`('returns $expected when $a is added $b', ({a, b, expected}) => {
547
+
expect(a + b).toBe(expected);
548
+
});
549
+
```
550
+
551
+
### `test.concurrent.only.each(table)(name, fn)`
552
+
553
+
Also under the alias: `it.concurrent.only.each(table)(name, fn)`
554
+
555
+
Use `test.concurrent.only.each` if you want to only run specific tests with different test data concurrently.
556
+
557
+
`test.concurrent.only.each` is available with two APIs:
558
+
559
+
#### `test.concurrent.only.each(table)(name, fn)`
560
+
561
+
```js
562
+
test.concurrent.only.each([
563
+
[1, 1, 2],
564
+
[1, 2, 3],
565
+
[2, 1, 3],
566
+
])('.add(%i, %i)', async (a, b, expected) => {
567
+
expect(a + b).toBe(expected);
568
+
});
569
+
570
+
test('will not be ran', () => {
571
+
expect(1/0).toBe(Infinity);
572
+
});
573
+
```
574
+
575
+
#### `` test.only.each`table`(name, fn) ``
576
+
577
+
```js
578
+
test.concurrent.only.each`
579
+
a | b | expected
580
+
${1} | ${1} | ${2}
581
+
${1} | ${2} | ${3}
582
+
${2} | ${1} | ${3}
583
+
`('returns $expected when $a is added $b', async ({a, b, expected}) => {
584
+
expect(a + b).toBe(expected);
585
+
});
586
+
587
+
test('will not be ran', () => {
588
+
expect(1/0).toBe(Infinity);
589
+
});
590
+
```
591
+
592
+
### `test.concurrent.skip.each(table)(name, fn)`
593
+
594
+
Also under the alias: `it.concurrent.skip.each(table)(name, fn)`
595
+
596
+
Use `test.concurrent.skip.each` if you want to stop running a collection of asynchronous data driven tests.
597
+
598
+
`test.concurrent.skip.each` is available with two APIs:
0 commit comments