From a05c8d7381bfd62573a820d70ef57667bfd43dfa Mon Sep 17 00:00:00 2001 From: M4rk9696 Date: Sun, 12 Jan 2020 15:20:56 +0530 Subject: [PATCH] Add tests for jest-each and jasmine --- e2e/__tests__/jasmineAsync.test.ts | 8 ++++ .../__tests__/concurrent-each.test.js | 25 ++++++++++ .../__tests__/concurrent.test.js | 16 +++++++ .../__snapshots__/array.test.ts.snap | 16 +++++++ .../__snapshots__/template.test.ts.snap | 47 +++++++++++++++++++ .../jest-each/src/__tests__/array.test.ts | 3 ++ .../jest-each/src/__tests__/template.test.ts | 3 ++ 7 files changed, 118 insertions(+) create mode 100644 e2e/jasmine-async/__tests__/concurrent-each.test.js diff --git a/e2e/__tests__/jasmineAsync.test.ts b/e2e/__tests__/jasmineAsync.test.ts index fb869f65cd06..c066d90fc8cb 100644 --- a/e2e/__tests__/jasmineAsync.test.ts +++ b/e2e/__tests__/jasmineAsync.test.ts @@ -115,6 +115,14 @@ describe('async jasmine', () => { expect(json.testResults[0].message).toMatch(/concurrent test fails/); }); + it('works with concurrent.each', () => { + const {json} = runWithJson('jasmine-async', ['concurrent-each.test.js']); + expect(json.numTotalTests).toBe(2); + expect(json.numPassedTests).toBe(1); + expect(json.numFailedTests).toBe(0); + expect(json.numPendingTests).toBe(1); + }); + it("doesn't execute more than 5 tests simultaneously", () => { const {json} = runWithJson('jasmine-async', ['concurrent-many.test.js']); expect(json.numTotalTests).toBe(10); diff --git a/e2e/jasmine-async/__tests__/concurrent-each.test.js b/e2e/jasmine-async/__tests__/concurrent-each.test.js new file mode 100644 index 000000000000..aad225234657 --- /dev/null +++ b/e2e/jasmine-async/__tests__/concurrent-each.test.js @@ -0,0 +1,25 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. 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. + */ + +'use strict'; + +it.concurrent.each( + [ + [1, 2], + [2, 3], + ], + 'adds one to number', + Promise.resolve() +); +it.concurrent.skip.each( + [ + [1, 2], + [2, 3], + ], + 'should skip this test', + Promise.resolve() +); diff --git a/e2e/jasmine-async/__tests__/concurrent.test.js b/e2e/jasmine-async/__tests__/concurrent.test.js index ef0cc1ba7b10..d3a081499e4a 100644 --- a/e2e/jasmine-async/__tests__/concurrent.test.js +++ b/e2e/jasmine-async/__tests__/concurrent.test.js @@ -11,3 +11,19 @@ it.concurrent('one', () => Promise.resolve()); it.concurrent.skip('two', () => Promise.resolve()); it.concurrent('three', () => Promise.resolve()); it.concurrent('concurrent test fails', () => Promise.reject()); +it.concurrent.each( + [ + [1, 2], + [2, 3], + ], + 'adds one to number', + Promise.resolve() +); +it.concurrent.skip.each( + [ + [1, 2], + [2, 3], + ], + 'should skip this test', + Promise.resolve() +); diff --git a/packages/jest-each/src/__tests__/__snapshots__/array.test.ts.snap b/packages/jest-each/src/__tests__/__snapshots__/array.test.ts.snap index d779a5e5df50..8ceacb9b80f6 100644 --- a/packages/jest-each/src/__tests__/__snapshots__/array.test.ts.snap +++ b/packages/jest-each/src/__tests__/__snapshots__/array.test.ts.snap @@ -60,6 +60,10 @@ Instead was called with: undefined " `; +exports[`jest-each .it.concurrent throws an error when called with an empty array 1`] = `"Cannot read property 'mock' of undefined"`; + +exports[`jest-each .it.concurrent throws an error when not called with an array 1`] = `"Cannot read property 'mock' of undefined"`; + exports[`jest-each .it.only throws an error when called with an empty array 1`] = ` "Error: \`.each\` called with an empty Array of table data. " @@ -84,6 +88,18 @@ Instead was called with: undefined " `; +exports[`jest-each .test.concurrent throws an error when called with an empty array 1`] = ` +"Error: \`.each\` called with an empty Array of table data. +" +`; + +exports[`jest-each .test.concurrent throws an error when not called with an array 1`] = ` +"\`.each\` must be called with an Array or Tagged Template Literal. + +Instead was called with: undefined +" +`; + exports[`jest-each .test.only throws an error when called with an empty array 1`] = ` "Error: \`.each\` called with an empty Array of table data. " diff --git a/packages/jest-each/src/__tests__/__snapshots__/template.test.ts.snap b/packages/jest-each/src/__tests__/__snapshots__/template.test.ts.snap index f5097aa6218d..02cc0e70987c 100644 --- a/packages/jest-each/src/__tests__/__snapshots__/template.test.ts.snap +++ b/packages/jest-each/src/__tests__/__snapshots__/template.test.ts.snap @@ -195,6 +195,14 @@ exports[`jest-each .it throws error when there are no arguments for given headin " `; +exports[`jest-each .it.concurrent throws an error when called with an empty string 1`] = `"Cannot read property 'mock' of undefined"`; + +exports[`jest-each .it.concurrent throws error when there are fewer arguments than headings over multiple rows 1`] = `"Cannot read property 'mock' of undefined"`; + +exports[`jest-each .it.concurrent throws error when there are fewer arguments than headings when given one row 1`] = `"Cannot read property 'mock' of undefined"`; + +exports[`jest-each .it.concurrent throws error when there are no arguments for given headings 1`] = `"Cannot read property 'mock' of undefined"`; + exports[`jest-each .it.only throws an error when called with an empty string 1`] = ` "Error: \`.each\` called with an empty Tagged Template Literal of table data. " @@ -273,6 +281,45 @@ exports[`jest-each .test throws error when there are no arguments for given head " `; +exports[`jest-each .test.concurrent throws an error when called with an empty string 1`] = ` +"Error: \`.each\` called with an empty Tagged Template Literal of table data. +" +`; + +exports[`jest-each .test.concurrent 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[`jest-each .test.concurrent 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[`jest-each .test.concurrent throws error when there are no arguments for given headings 1`] = ` +"Error: \`.each\` called with a Tagged Template Literal with no data, remember to interpolate with \${expression} syntax. +" +`; + exports[`jest-each .test.only throws an error when called with an empty string 1`] = ` "Error: \`.each\` called with an empty Tagged Template Literal of table data. " diff --git a/packages/jest-each/src/__tests__/array.test.ts b/packages/jest-each/src/__tests__/array.test.ts index 765aa54ec276..3d1807c061c5 100644 --- a/packages/jest-each/src/__tests__/array.test.ts +++ b/packages/jest-each/src/__tests__/array.test.ts @@ -33,14 +33,17 @@ const getGlobalTestMocks = () => { globals.describe.only = jest.fn(); globals.describe.skip = jest.fn(); globals.test.concurrent = jest.fn(); + globals.it.concurrent = jest.fn(); return globals; }; describe('jest-each', () => { [ ['test'], + ['test', 'concurrent'], ['test', 'only'], ['it'], + ['it', 'concurrent'], ['fit'], ['it', 'only'], ['describe'], diff --git a/packages/jest-each/src/__tests__/template.test.ts b/packages/jest-each/src/__tests__/template.test.ts index 7cf025dc625c..d77571883f9a 100644 --- a/packages/jest-each/src/__tests__/template.test.ts +++ b/packages/jest-each/src/__tests__/template.test.ts @@ -32,14 +32,17 @@ const getGlobalTestMocks = () => { globals.describe.only = jest.fn(); globals.describe.skip = jest.fn(); globals.test.concurrent = jest.fn(); + globals.it.concurrent = jest.fn(); return globals; }; describe('jest-each', () => { [ ['test'], + ['test', 'concurrent'], ['test', 'only'], ['it'], + ['it', 'concurrent'], ['fit'], ['it', 'only'], ['describe'],