diff --git a/CHANGELOG.md b/CHANGELOG.md index d4b2fb75c803..58ed9281df19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - `[jest-config]` Update default config for testURL from 'about:blank' to 'http://localhost' to address latest JSDOM security warning. ([#6792](https://github.com/facebook/jest/pull/6792)) - `[jest-cli]` Fix `testMatch` not working with negations ([#6648](https://github.com/facebook/jest/pull/6648)) - `[jest-cli]` Don't report promises as open handles ([#6716](https://github.com/facebook/jest/pull/6716)) +- `[jest-each]` Add timeout support to parameterised tests ([#6660](https://github.com/facebook/jest/pull/6660)) ## 23.4.2 diff --git a/docs/GlobalAPI.md b/docs/GlobalAPI.md index b87c9a7aa548..1cfdfc642b56 100644 --- a/docs/GlobalAPI.md +++ b/docs/GlobalAPI.md @@ -222,13 +222,13 @@ describe('binaryStringToNumber', () => { }); ``` -### `describe.each(table)(name, fn)` +### `describe.each(table)(name, fn, timeout)` Use `describe.each` if you keep duplicating the same test suites with different data. `describe.each` allows you to write the test suite once and pass data in. `describe.each` is available with two APIs: -#### 1. `describe.each(table)(name, fn)` +#### 1. `describe.each(table)(name, fn, timeout)` - `table`: `Array` of Arrays with the arguments that are passed into the `fn` for each row. - _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]]` @@ -244,6 +244,7 @@ Use `describe.each` if you keep duplicating the same test suites with different - `%#` - Index of the test case. - `%%` - single percent sign ('%'). This does not consume an argument. - `fn`: `Function` the suite of tests to be ran, this is the function that will receive the parameters in each row as function arguments. +- 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._ Example: @@ -266,7 +267,7 @@ describe.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])( ); ``` -#### 2. `` describe.each`table`(name, fn) `` +#### 2. `` describe.each`table`(name, fn, timeout) `` - `table`: `Tagged Template Literal` - First row of variable name column headings separated with `|` @@ -274,6 +275,7 @@ describe.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])( - `name`: `String` the title of the test suite, use `$variable` to inject test data into the suite title from the tagged template expressions. - To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value` - `fn`: `Function` the suite of tests to be ran, this is the function that will receive the test data object. +- 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._ Example: @@ -468,7 +470,7 @@ test('has lemon in it', () => { Even though the call to `test` will return right away, the test doesn't complete until the promise resolves as well. -### `test.each(table)(name, fn)` +### `test.each(table)(name, fn, timeout)` Also under the alias: `it.each(table)(name, fn)` and `` it.each`table`(name, fn) `` @@ -476,7 +478,7 @@ Use `test.each` if you keep duplicating the same test with different data. `test `test.each` is available with two APIs: -#### 1. `test.each(table)(name, fn)` +#### 1. `test.each(table)(name, fn, timeout)` - `table`: `Array` of Arrays with the arguments that are passed into the test `fn` for each row. - _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]]` @@ -492,6 +494,7 @@ Use `test.each` if you keep duplicating the same test with different data. `test - `%#` - Index of the test case. - `%%` - single percent sign ('%'). This does not consume an argument. - `fn`: `Function` the test to be ran, this is the function that will receive the parameters in each row as function arguments. +- 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._ Example: @@ -504,7 +507,7 @@ test.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])( ); ``` -#### 2. `` test.each`table`(name, fn) `` +#### 2. `` test.each`table`(name, fn, timeout) `` - `table`: `Tagged Template Literal` - First row of variable name column headings separated with `|` @@ -512,6 +515,7 @@ test.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])( - `name`: `String` the title of the test, use `$variable` to inject test data into the test title from the tagged template expressions. - To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value` - `fn`: `Function` the test to be ran, this is the function that will receive the test data object. +- 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._ Example: diff --git a/packages/jest-each/src/__tests__/array.test.js b/packages/jest-each/src/__tests__/array.test.js index 2be82eef691a..65a41f627d59 100644 --- a/packages/jest-each/src/__tests__/array.test.js +++ b/packages/jest-each/src/__tests__/array.test.js @@ -52,6 +52,7 @@ describe('jest-each', () => { expect(globalMock).toHaveBeenCalledWith( 'expected string', expectFunction, + undefined, ); }); @@ -66,10 +67,12 @@ describe('jest-each', () => { expect(globalMock).toHaveBeenCalledWith( 'expected string', expectFunction, + undefined, ); expect(globalMock).toHaveBeenCalledWith( 'expected string', expectFunction, + undefined, ); }); @@ -111,12 +114,14 @@ describe('jest-each', () => { foo: 'bar', })} () => {} [] Infinity NaN 0`, expectFunction, + undefined, ); expect(globalMock).toHaveBeenCalledWith( `expected string: world 1 null undefined 1.2 ${JSON.stringify({ baz: 'qux', })} () => {} [] Infinity NaN 1`, expectFunction, + undefined, ); }); @@ -134,10 +139,12 @@ describe('jest-each', () => { expect(globalMock).toHaveBeenCalledWith( 'expected string: hello', expectFunction, + undefined, ); expect(globalMock).toHaveBeenCalledWith( 'expected string: world', expectFunction, + undefined, ); }); @@ -157,12 +164,14 @@ describe('jest-each', () => { 'pretty2', )}`, expectFunction, + undefined, ); expect(globalMock).toHaveBeenCalledWith( `expected string: string1 ${pretty('pretty1')} string2 ${pretty( 'pretty2', )}`, expectFunction, + undefined, ); }); @@ -180,10 +189,12 @@ describe('jest-each', () => { expect(globalMock).toHaveBeenCalledWith( `expected string: string1 ${pretty('pretty1')} string2 %p`, expectFunction, + undefined, ); expect(globalMock).toHaveBeenCalledWith( `expected string: string1 ${pretty('pretty1')} string2 %p`, expectFunction, + undefined, ); }); @@ -237,6 +248,20 @@ describe('jest-each', () => { }); get(globalTestMocks, keyPath).mock.calls[0][1]('DONE'); }); + + test('calls global with given timeout', () => { + const globalTestMocks = getGlobalTestMocks(); + const eachObject = each.withGlobal(globalTestMocks)([['hello']]); + + const testFunction = get(eachObject, keyPath); + testFunction('some test', noop, 10000); + const globalMock = get(globalTestMocks, keyPath); + expect(globalMock).toHaveBeenCalledWith( + 'some test', + expect.any(Function), + 10000, + ); + }); }); }); @@ -278,6 +303,7 @@ describe('jest-each', () => { expect(globalMock).toHaveBeenCalledWith( 'expected string', expectFunction, + undefined, ); }); @@ -292,6 +318,7 @@ describe('jest-each', () => { expect(globalMock).toHaveBeenCalledWith( 'expected string', expectFunction, + undefined, ); }); @@ -309,10 +336,12 @@ describe('jest-each', () => { expect(globalMock).toHaveBeenCalledWith( 'expected string: hello 1', expectFunction, + undefined, ); expect(globalMock).toHaveBeenCalledWith( 'expected string: world 2', expectFunction, + undefined, ); }); }); diff --git a/packages/jest-each/src/__tests__/template.test.js b/packages/jest-each/src/__tests__/template.test.js index d9d4129a59f5..7ec6b44dfe3e 100644 --- a/packages/jest-each/src/__tests__/template.test.js +++ b/packages/jest-each/src/__tests__/template.test.js @@ -91,6 +91,7 @@ describe('jest-each', () => { expect(globalMock).toHaveBeenCalledWith( 'expected string', expectFunction, + undefined, ); }); @@ -109,10 +110,12 @@ describe('jest-each', () => { expect(globalMock).toHaveBeenCalledWith( 'expected string', expectFunction, + undefined, ); expect(globalMock).toHaveBeenCalledWith( 'expected string', expectFunction, + undefined, ); }); @@ -131,10 +134,12 @@ describe('jest-each', () => { expect(globalMock).toHaveBeenCalledWith( 'expected string: a=0, b=1, expected=1', expectFunction, + undefined, ); expect(globalMock).toHaveBeenCalledWith( 'expected string: a=1, b=1, expected=2', expectFunction, + undefined, ); }); @@ -156,10 +161,12 @@ describe('jest-each', () => { expect(globalMock).toHaveBeenCalledWith( 'add(0, 1) expected string: a=0, b=1, expected=1', expectFunction, + undefined, ); expect(globalMock).toHaveBeenCalledWith( 'add(1, 1) expected string: a=1, b=1, expected=2', expectFunction, + undefined, ); }); @@ -177,6 +184,7 @@ describe('jest-each', () => { expect(globalMock).toHaveBeenCalledWith( 'interpolates object keyPath to value: "baz"', expectFunction, + undefined, ); }); @@ -194,6 +202,7 @@ describe('jest-each', () => { expect(globalMock).toHaveBeenCalledWith( 'interpolates object keyPath to value: {"bar": "baz"}', expectFunction, + undefined, ); }); @@ -234,6 +243,23 @@ describe('jest-each', () => { }); get(globalTestMocks, keyPath).mock.calls[0][1]('DONE'); }); + + test('calls global with given timeout', () => { + const globalTestMocks = getGlobalTestMocks(); + const eachObject = each.withGlobal(globalTestMocks)` + a | b | expected + ${0} | ${1} | ${1} + `; + + const testFunction = get(eachObject, keyPath); + testFunction('some test', noop, 10000); + const globalMock = get(globalTestMocks, keyPath); + expect(globalMock).toHaveBeenCalledWith( + 'some test', + expect.any(Function), + 10000, + ); + }); }); }); @@ -278,6 +304,7 @@ describe('jest-each', () => { expect(globalMock).toHaveBeenCalledWith( 'expected string', expectFunction, + undefined, ); }); @@ -296,10 +323,12 @@ describe('jest-each', () => { expect(globalMock).toHaveBeenCalledWith( 'expected string', expectFunction, + undefined, ); expect(globalMock).toHaveBeenCalledWith( 'expected string', expectFunction, + undefined, ); }); @@ -318,10 +347,12 @@ describe('jest-each', () => { expect(globalMock).toHaveBeenCalledWith( 'expected string: a=0, b=1, expected=1', expectFunction, + undefined, ); expect(globalMock).toHaveBeenCalledWith( 'expected string: a=1, b=1, expected=2', expectFunction, + undefined, ); }); }); diff --git a/packages/jest-each/src/bind.js b/packages/jest-each/src/bind.js index 03b8b7b53087..df1221b38065 100644 --- a/packages/jest-each/src/bind.js +++ b/packages/jest-each/src/bind.js @@ -24,13 +24,13 @@ const PRETTY_PLACEHOLDER = '%p'; const INDEX_PLACEHOLDER = '%#'; export default (cb: Function) => (...args: any) => - function eachBind(title: string, test: Function): void { + function eachBind(title: string, test: Function, timeout: number): void { if (args.length === 1) { const table: Table = args[0].every(Array.isArray) ? args[0] : args[0].map(entry => [entry]); return table.forEach((row, i) => - cb(arrayFormat(title, i, ...row), applyRestParams(row, test)), + cb(arrayFormat(title, i, ...row), applyRestParams(row, test), timeout), ); } @@ -66,7 +66,7 @@ export default (cb: Function) => (...args: any) => } return table.forEach(row => - cb(interpolate(title, row), applyObjectParams(row, test)), + cb(interpolate(title, row), applyObjectParams(row, test), timeout), ); }; diff --git a/packages/jest-each/src/index.js b/packages/jest-each/src/index.js index ae04951f9d1a..333651aae902 100644 --- a/packages/jest-each/src/index.js +++ b/packages/jest-each/src/index.js @@ -21,13 +21,13 @@ type GlobalCallbacks = { }; const install = (g: GlobalCallbacks, ...args: Array) => { - const test = (title: string, test: Function) => - bind(g.test)(...args)(title, test); + const test = (title: string, test: Function, timeout: number) => + bind(g.test)(...args)(title, test, timeout); test.skip = bind(g.test.skip)(...args); test.only = bind(g.test.only)(...args); - const it = (title: string, test: Function) => - bind(g.it)(...args)(title, test); + const it = (title: string, test: Function, timeout: number) => + bind(g.it)(...args)(title, test, timeout); it.skip = bind(g.it.skip)(...args); it.only = bind(g.it.only)(...args); @@ -35,8 +35,8 @@ const install = (g: GlobalCallbacks, ...args: Array) => { const fit = bind(g.fit)(...args); const xtest = bind(g.xtest)(...args); - const describe = (title: string, suite: Function) => - bind(g.describe)(...args)(title, suite); + const describe = (title: string, suite: Function, timeout: number) => + bind(g.describe)(...args)(title, suite, timeout); describe.skip = bind(g.describe.skip)(...args); describe.only = bind(g.describe.only)(...args); const fdescribe = bind(g.fdescribe)(...args); diff --git a/packages/jest-jasmine2/src/__tests__/__snapshots__/each.test.js.snap b/packages/jest-jasmine2/src/__tests__/__snapshots__/each.test.js.snap deleted file mode 100644 index f3b4ed19fd97..000000000000 --- a/packages/jest-jasmine2/src/__tests__/__snapshots__/each.test.js.snap +++ /dev/null @@ -1,175 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`installEach .describe Table Tagged Template Literal throws error when there are fewer arguments than headings over multiple rows 1`] = ` -"Not enough arguments supplied for given headings: -a | b | expected - -Received: -Array [ - 0, - 1, - 1, - 1, - 1, -] - -Missing 2 arguments" -`; - -exports[`installEach .describe Table Tagged Template Literal throws error when there are fewer arguments than headings when given one row 1`] = ` -"Not enough arguments supplied for given headings: -a | b | expected - -Received: -Array [ - 0, - 1, -] - -Missing 2 arguments" -`; - -exports[`installEach .fdescribe Table Tagged Template Literal throws error when there are fewer arguments than headings over multiple rows 1`] = ` -"Not enough arguments supplied for given headings: -a | b | expected - -Received: -Array [ - 0, - 1, - 1, - 1, - 1, -] - -Missing 2 arguments" -`; - -exports[`installEach .fdescribe Table Tagged Template Literal throws error when there are fewer arguments than headings when given one row 1`] = ` -"Not enough arguments supplied for given headings: -a | b | expected - -Received: -Array [ - 0, - 1, -] - -Missing 2 arguments" -`; - -exports[`installEach .fit Table Tagged Template Literal throws error when there are fewer arguments than headings over multiple rows 1`] = ` -"Not enough arguments supplied for given headings: -a | b | expected - -Received: -Array [ - 0, - 1, - 1, - 1, - 1, -] - -Missing 2 arguments" -`; - -exports[`installEach .fit Table Tagged Template Literal throws error when there are fewer arguments than headings when given one row 1`] = ` -"Not enough arguments supplied for given headings: -a | b | expected - -Received: -Array [ - 0, - 1, -] - -Missing 2 arguments" -`; - -exports[`installEach .it Table Tagged Template Literal throws error when there are fewer arguments than headings over multiple rows 1`] = ` -"Not enough arguments supplied for given headings: -a | b | expected - -Received: -Array [ - 0, - 1, - 1, - 1, - 1, -] - -Missing 2 arguments" -`; - -exports[`installEach .it Table Tagged Template Literal throws error when there are fewer arguments than headings when given one row 1`] = ` -"Not enough arguments supplied for given headings: -a | b | expected - -Received: -Array [ - 0, - 1, -] - -Missing 2 arguments" -`; - -exports[`installEach .xdescribe Table Tagged Template Literal throws error when there are fewer arguments than headings over multiple rows 1`] = ` -"Not enough arguments supplied for given headings: -a | b | expected - -Received: -Array [ - 0, - 1, - 1, - 1, - 1, -] - -Missing 2 arguments" -`; - -exports[`installEach .xdescribe Table Tagged Template Literal throws error when there are fewer arguments than headings when given one row 1`] = ` -"Not enough arguments supplied for given headings: -a | b | expected - -Received: -Array [ - 0, - 1, -] - -Missing 2 arguments" -`; - -exports[`installEach .xit Table Tagged Template Literal throws error when there are fewer arguments than headings over multiple rows 1`] = ` -"Not enough arguments supplied for given headings: -a | b | expected - -Received: -Array [ - 0, - 1, - 1, - 1, - 1, -] - -Missing 2 arguments" -`; - -exports[`installEach .xit Table Tagged Template Literal throws error when there are fewer arguments than headings when given one row 1`] = ` -"Not enough arguments supplied for given headings: -a | b | expected - -Received: -Array [ - 0, - 1, -] - -Missing 2 arguments" -`; diff --git a/packages/jest-jasmine2/src/__tests__/each.test.js b/packages/jest-jasmine2/src/__tests__/each.test.js deleted file mode 100644 index 49450409c36c..000000000000 --- a/packages/jest-jasmine2/src/__tests__/each.test.js +++ /dev/null @@ -1,272 +0,0 @@ -/** - * Copyright (c) 2018-present, Facebook, Inc. All rights reserved. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - */ - -import installEach from '../each'; - -const noop = () => {}; -const expectFunction = expect.any(Function); - -describe('installEach', () => { - [ - ['it'], - ['fit'], - ['xit'], - ['describe'], - ['fdescribe'], - ['xdescribe'], - ].forEach(keyPath => { - describe(`.${keyPath.join('.')}`, () => { - const getEnvironmentMock = () => ({ - global: { - describe: jest.fn(), - fdescribe: jest.fn(), - fit: jest.fn(), - it: jest.fn(), - xdescribe: jest.fn(), - xit: jest.fn(), - }, - }); - - describe('Table Array', () => { - test('calls global function with given title', () => { - const environmentMock = getEnvironmentMock(); - installEach(environmentMock); - - const globalMock = environmentMock.global[keyPath]; - - globalMock.each([[]])('expected string', noop); - - expect(globalMock).toHaveBeenCalledTimes(1); - expect(globalMock).toHaveBeenCalledWith( - 'expected string', - expectFunction, - ); - }); - - test('calls global function with given title when multiple tests cases exist', () => { - const environmentMock = getEnvironmentMock(); - installEach(environmentMock); - - const globalMock = environmentMock.global[keyPath]; - - globalMock.each([[], []])('expected string', noop); - - expect(globalMock).toHaveBeenCalledTimes(2); - expect(globalMock).toHaveBeenCalledWith( - 'expected string', - expectFunction, - ); - expect(globalMock).toHaveBeenCalledWith( - 'expected string', - expectFunction, - ); - }); - - test('calls global function with title containing param values when using sprintf format', () => { - const environmentMock = getEnvironmentMock(); - installEach(environmentMock); - - const globalMock = environmentMock.global[keyPath]; - - globalMock.each([['hello', 1], ['world', 2]])( - 'expected string: %s %s', - noop, - ); - - expect(globalMock).toHaveBeenCalledTimes(2); - expect(globalMock).toHaveBeenCalledWith( - 'expected string: hello 1', - expectFunction, - ); - expect(globalMock).toHaveBeenCalledWith( - 'expected string: world 2', - expectFunction, - ); - }); - - test('calls global function with cb function containing all parameters of each test case', () => { - const environmentMock = getEnvironmentMock(); - installEach(environmentMock); - - const globalMock = environmentMock.global[keyPath]; - const testCallBack = jest.fn(); - globalMock.each([['hello', 'world'], ['joe', 'bloggs']])( - 'expected string: %s %s', - testCallBack, - ); - - globalMock.mock.calls[0][1](); - expect(testCallBack).toHaveBeenCalledTimes(1); - expect(testCallBack).toHaveBeenCalledWith('hello', 'world'); - - globalMock.mock.calls[1][1](); - expect(testCallBack).toHaveBeenCalledTimes(2); - expect(testCallBack).toHaveBeenCalledWith('joe', 'bloggs'); - }); - - test('calls global function with async done when cb function has more args than params of given test row', () => { - expect.hasAssertions(); - const environmentMock = getEnvironmentMock(); - installEach(environmentMock); - - const globalMock = environmentMock.global[keyPath]; - globalMock.each([['hello']])('a title', (hello, done) => { - expect(hello).toBe('hello'); - expect(done).toBe('DONE'); - }); - - globalMock.mock.calls[0][1]('DONE'); - }); - }); - - describe('Table Tagged Template Literal', () => { - test('throws error when there are fewer arguments than headings when given one row', () => { - const environmentMock = getEnvironmentMock(); - installEach(environmentMock); - - const globalMock = environmentMock.global[keyPath]; - const testCallBack = jest.fn(); - - globalMock.each` - a | b | expected - ${0} | ${1} | - `('this will blow up :(', testCallBack); - - expect(() => - globalMock.mock.calls[0][1](), - ).toThrowErrorMatchingSnapshot(); - expect(testCallBack).not.toHaveBeenCalled(); - }); - - test('throws error when there are fewer arguments than headings over multiple rows', () => { - const environmentMock = getEnvironmentMock(); - installEach(environmentMock); - - const globalMock = environmentMock.global[keyPath]; - const testCallBack = jest.fn(); - - globalMock.each` - a | b | expected - ${0} | ${1} | ${1} - ${1} | ${1} | - `('this will blow up :(', testCallBack); - - expect(() => - globalMock.mock.calls[0][1](), - ).toThrowErrorMatchingSnapshot(); - expect(testCallBack).not.toHaveBeenCalled(); - }); - - test('calls global function with given title', () => { - const environmentMock = getEnvironmentMock(); - installEach(environmentMock); - - const globalMock = environmentMock.global[keyPath]; - - globalMock.each` - a | b | expected - ${0} | ${1} | ${1} - `('expected string', noop); - - expect(globalMock).toHaveBeenCalledTimes(1); - expect(globalMock).toHaveBeenCalledWith( - 'expected string', - expectFunction, - ); - }); - - test('calls global function with given title when multiple tests cases exist', () => { - const environmentMock = getEnvironmentMock(); - installEach(environmentMock); - - const globalMock = environmentMock.global[keyPath]; - - globalMock.each` - a | b | expected - ${0} | ${1} | ${1} - ${1} | ${1} | ${2} - `('expected string', noop); - - expect(globalMock).toHaveBeenCalledTimes(2); - expect(globalMock).toHaveBeenCalledWith( - 'expected string', - expectFunction, - ); - expect(globalMock).toHaveBeenCalledWith( - 'expected string', - expectFunction, - ); - }); - - test('calls global function with title containing param values when using $variable format', () => { - const environmentMock = getEnvironmentMock(); - installEach(environmentMock); - - const globalMock = environmentMock.global[keyPath]; - - globalMock.each` - a | b | expected - ${0} | ${1} | ${1} - ${1} | ${1} | ${2} - `('expected string: a=$a, b=$b, expected=$expected', noop); - - expect(globalMock).toHaveBeenCalledTimes(2); - expect(globalMock).toHaveBeenCalledWith( - 'expected string: a=0, b=1, expected=1', - expectFunction, - ); - expect(globalMock).toHaveBeenCalledWith( - 'expected string: a=1, b=1, expected=2', - expectFunction, - ); - }); - - test('calls global function with cb function containing all parameters of each test case', () => { - const environmentMock = getEnvironmentMock(); - installEach(environmentMock); - - const globalMock = environmentMock.global[keyPath]; - const testCallBack = jest.fn(); - globalMock.each` - a | b | expected - ${0} | ${1} | ${1} - ${1} | ${1} | ${2} - `('expected string: %s %s', testCallBack); - - globalMock.mock.calls[0][1](); - expect(testCallBack).toHaveBeenCalledTimes(1); - - expect(testCallBack).toHaveBeenCalledWith({a: 0, b: 1, expected: 1}); - - globalMock.mock.calls[1][1](); - expect(testCallBack).toHaveBeenCalledTimes(2); - expect(testCallBack).toHaveBeenCalledWith({a: 1, b: 1, expected: 2}); - }); - - test('calls global function with async done when cb function has more than one argument', () => { - expect.hasAssertions(); - const environmentMock = getEnvironmentMock(); - installEach(environmentMock); - - const globalMock = environmentMock.global[keyPath]; - globalMock.each` - a | b | expected - ${0} | ${1} | ${1} - `('a title', ({a, b, expected}, done) => { - expect(a).toBe(0); - expect(b).toBe(1); - expect(expected).toBe(1); - expect(done).toBe('DONE'); - }); - - globalMock.mock.calls[0][1]('DONE'); - }); - }); - }); - }); -});