From 838bdae8383d418d7fc1d2f65dd700f21094015f Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Mon, 9 Jul 2018 15:52:42 +0100 Subject: [PATCH 1/5] Add test timeout to jest-each --- .../jest-each/src/__tests__/array.test.js | 29 +++++++++++++++++ .../jest-each/src/__tests__/template.test.js | 31 +++++++++++++++++++ packages/jest-each/src/bind.js | 6 ++-- packages/jest-each/src/index.js | 12 +++---- 4 files changed, 69 insertions(+), 9 deletions(-) diff --git a/packages/jest-each/src/__tests__/array.test.js b/packages/jest-each/src/__tests__/array.test.js index 6b8fb1ef1adc..49ffe4e024d5 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`, expectFunction, + undefined, ); expect(globalMock).toHaveBeenCalledWith( `expected string: world 1 null undefined 1.2 ${JSON.stringify({ baz: 'qux', })} () => {} [] Infinity NaN`, 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 gloabl 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..1489db4e5974 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 gloabl 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 1d72d097f394..414836f0762c 100644 --- a/packages/jest-each/src/bind.js +++ b/packages/jest-each/src/bind.js @@ -23,13 +23,13 @@ const SUPPORTED_PLACEHOLDERS = /%[sdifjoOp%]/g; const PRETTY_PLACEHOLDER = '%p'; 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 => - cb(arrayFormat(title, ...row), applyRestParams(row, test)), + cb(arrayFormat(title, ...row), applyRestParams(row, test), timeout), ); } @@ -65,7 +65,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); From 00f522bccae3adab502f8ace0cb8dea9a91c6637 Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Mon, 9 Jul 2018 15:55:15 +0100 Subject: [PATCH 2/5] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 409a0117f35b..a7bbe3b35256 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Fixes +- `[jest-each]` Add timeout support to parameterised tests ([#6660](https://github.com/facebook/jest/pull/6660)) - `[jest-runner]` Force parallel runs for watch mode, to avoid TTY freeze ([#6647](https://github.com/facebook/jest/pull/6647)) - `[jest-cli]` properly reprint resolver errors in watch mode ([#6407](https://github.com/facebook/jest/pull/6407)) - `[jest-cli]` Write configuration to stdout when the option was explicitly passed to Jest ([#6447](https://github.com/facebook/jest/pull/6447)) From c42eb50d1a6aa9f080171d23e80ed63a4df2ae46 Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Mon, 9 Jul 2018 17:57:58 +0100 Subject: [PATCH 3/5] Remove duplicate tests --- .../__tests__/__snapshots__/each.test.js.snap | 175 ----------- .../jest-jasmine2/src/__tests__/each.test.js | 272 ------------------ 2 files changed, 447 deletions(-) delete mode 100644 packages/jest-jasmine2/src/__tests__/__snapshots__/each.test.js.snap delete mode 100644 packages/jest-jasmine2/src/__tests__/each.test.js 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'); - }); - }); - }); - }); -}); From 9751937fe7d3625c3006ac31afcab914d6e8c82f Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Tue, 10 Jul 2018 09:43:19 +0100 Subject: [PATCH 4/5] Fix typo and add docs --- docs/GlobalAPI.md | 16 ++++++++++------ packages/jest-each/src/__tests__/array.test.js | 2 +- .../jest-each/src/__tests__/template.test.js | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/docs/GlobalAPI.md b/docs/GlobalAPI.md index 98414cef4145..46ad8f6f7073 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]]` @@ -243,6 +243,7 @@ Use `describe.each` if you keep duplicating the same test suites with different - `%o` - Object. - `%%` - 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 before aborting. _Note: The default timeout is 5 seconds._ Example: @@ -265,7 +266,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 `|` @@ -273,6 +274,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 before aborting. _Note: The default timeout is 5 seconds._ Example: @@ -467,7 +469,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) `` @@ -475,7 +477,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]]` @@ -490,6 +492,7 @@ Use `test.each` if you keep duplicating the same test with different data. `test - `%o` - Object. - `%%` - 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 before aborting. _Note: The default timeout is 5 seconds._ Example: @@ -502,7 +505,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 `|` @@ -510,6 +513,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 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 49ffe4e024d5..83791e31fcec 100644 --- a/packages/jest-each/src/__tests__/array.test.js +++ b/packages/jest-each/src/__tests__/array.test.js @@ -249,7 +249,7 @@ describe('jest-each', () => { get(globalTestMocks, keyPath).mock.calls[0][1]('DONE'); }); - test('calls gloabl with given timeout', () => { + test('calls global with given timeout', () => { const globalTestMocks = getGlobalTestMocks(); const eachObject = each.withGlobal(globalTestMocks)([['hello']]); diff --git a/packages/jest-each/src/__tests__/template.test.js b/packages/jest-each/src/__tests__/template.test.js index 1489db4e5974..7ec6b44dfe3e 100644 --- a/packages/jest-each/src/__tests__/template.test.js +++ b/packages/jest-each/src/__tests__/template.test.js @@ -244,7 +244,7 @@ describe('jest-each', () => { get(globalTestMocks, keyPath).mock.calls[0][1]('DONE'); }); - test('calls gloabl with given timeout', () => { + test('calls global with given timeout', () => { const globalTestMocks = getGlobalTestMocks(); const eachObject = each.withGlobal(globalTestMocks)` a | b | expected From b48ccc9cec3d1df58f85cb6fadffe61c58cd46a2 Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Thu, 9 Aug 2018 10:33:46 +0100 Subject: [PATCH 5/5] Update timeout docs --- docs/GlobalAPI.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/GlobalAPI.md b/docs/GlobalAPI.md index 46ad8f6f7073..8d0631b56e52 100644 --- a/docs/GlobalAPI.md +++ b/docs/GlobalAPI.md @@ -243,7 +243,7 @@ Use `describe.each` if you keep duplicating the same test suites with different - `%o` - Object. - `%%` - 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 before aborting. _Note: The default timeout is 5 seconds._ +- 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: @@ -274,7 +274,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 before aborting. _Note: The default timeout is 5 seconds._ +- 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: @@ -492,7 +492,7 @@ Use `test.each` if you keep duplicating the same test with different data. `test - `%o` - Object. - `%%` - 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 before aborting. _Note: The default timeout is 5 seconds._ +- 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: @@ -513,7 +513,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 before aborting. _Note: The default timeout is 5 seconds._ +- 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: