From 0c22067d7fd5734ee0809d1d6dd8e46e165ac48f Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Tue, 1 May 2018 12:06:19 +0100 Subject: [PATCH] Add integration tests --- .../each/__tests__/each-exception.test.js | 17 ++++ .../each/__tests__/each-only.test.js | 39 ++++++++++ .../each/__tests__/each-skip.test.js | 39 ++++++++++ .../each/__tests__/failure.test.js | 55 +++++++++++++ .../each/__tests__/success.test.js | 55 +++++++++++++ integration-tests/each/package.json | 5 ++ .../__tests__/integration/each-only.test.js | 16 ---- .../__tests__/integration/each-skip.test.js | 16 ---- .../src/__tests__/integration/each.test.js | 77 ------------------- 9 files changed, 210 insertions(+), 109 deletions(-) create mode 100644 integration-tests/each/__tests__/each-exception.test.js create mode 100644 integration-tests/each/__tests__/each-only.test.js create mode 100644 integration-tests/each/__tests__/each-skip.test.js create mode 100644 integration-tests/each/__tests__/failure.test.js create mode 100644 integration-tests/each/__tests__/success.test.js create mode 100644 integration-tests/each/package.json delete mode 100644 packages/jest-jasmine2/src/__tests__/integration/each-only.test.js delete mode 100644 packages/jest-jasmine2/src/__tests__/integration/each-skip.test.js delete mode 100644 packages/jest-jasmine2/src/__tests__/integration/each.test.js diff --git a/integration-tests/each/__tests__/each-exception.test.js b/integration-tests/each/__tests__/each-exception.test.js new file mode 100644 index 000000000000..766fd719f649 --- /dev/null +++ b/integration-tests/each/__tests__/each-exception.test.js @@ -0,0 +1,17 @@ +/** + * 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. + */ + +it.each` + left | right + ${true} | ${true} + ${true} | +`( + 'throws exception when not enough arguments are supplied $left == $right', + ({left, right}) => { + expect(left).toBe(right); + } +); diff --git a/integration-tests/each/__tests__/each-only.test.js b/integration-tests/each/__tests__/each-only.test.js new file mode 100644 index 000000000000..a434a48f2b78 --- /dev/null +++ b/integration-tests/each/__tests__/each-only.test.js @@ -0,0 +1,39 @@ +/** + * 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. + */ + +it.only.each([[true, true], [true, true]])( + 'passes one row expected %s == %s', + (left, right) => { + expect(left).toBe(right); + } +); + +it.each([[true, false], [true, true]])( + 'Should not be ran: fails all rows expected %s == %s', + (left, right) => { + expect(left).toBe(right); + } +); + +it.only.each` + left | right + ${true} | ${true} + ${true} | ${true} +`('passes one row expected $left == $right', ({left, right}) => { + expect(left).toBe(right); +}); + +it.each` + left | right + ${true} | ${false} + ${true} | ${false} +`( + 'Should not be ran: fails all rows expected $left == $right', + ({left, right}) => { + expect(left).toBe(right); + } +); diff --git a/integration-tests/each/__tests__/each-skip.test.js b/integration-tests/each/__tests__/each-skip.test.js new file mode 100644 index 000000000000..08945a527331 --- /dev/null +++ b/integration-tests/each/__tests__/each-skip.test.js @@ -0,0 +1,39 @@ +/** + * 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. + */ + +it.each([[true, true], [true, true]])( + 'passes one row expected %s == %s', + (left, right) => { + expect(left).toBe(right); + } +); + +it.skip.each([[true, false], [true, true]])( + 'Should not be ran: fails all rows expected %s == %s', + (left, right) => { + expect(left).toBe(right); + } +); + +it.each` + left | right + ${true} | ${true} + ${true} | ${true} +`('passes one row expected $left == $right', ({left, right}) => { + expect(left).toBe(right); +}); + +it.skip.each` + left | right + ${true} | ${false} + ${true} | ${false} +`( + 'Should not be ran: fails all rows expected $left == $right', + ({left, right}) => { + expect(left).toBe(right); + } +); diff --git a/integration-tests/each/__tests__/failure.test.js b/integration-tests/each/__tests__/failure.test.js new file mode 100644 index 000000000000..1ab3069983ab --- /dev/null +++ b/integration-tests/each/__tests__/failure.test.js @@ -0,0 +1,55 @@ +/** + * 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. + */ + +it.each([[true, true], [true, false]])( + 'fails one row expected %s == %s', + (left, right) => { + expect(left).toBe(right); + } +); + +it.each([[true, false], [true, false]])( + 'fails all rows expected %s == %s', + (left, right) => { + expect(left).toBe(right); + } +); + +describe.each([[false, true], [true, false]])( + 'fails all rows expected %s == %s', + (left, right) => { + it('fails', () => { + expect(left).toBe(right); + }); + } +); + +it.each` + left | right + ${true} | ${false} + ${true} | ${true} +`('fails one row expected $left == $right', ({left, right}) => { + expect(left).toBe(right); +}); + +it.each` + left | right + ${true} | ${false} + ${true} | ${true} +`('fails all rows expected $left == $right', ({left, right}) => { + expect(left).toBe(right); +}); + +describe.each` + left | right + ${true} | ${false} + ${false} | ${true} +`('fails all rows expected $left == $right', ({left, right}) => { + it('fails ', () => { + expect(left).toBe(right); + }); +}); diff --git a/integration-tests/each/__tests__/success.test.js b/integration-tests/each/__tests__/success.test.js new file mode 100644 index 000000000000..9964f3c74c08 --- /dev/null +++ b/integration-tests/each/__tests__/success.test.js @@ -0,0 +1,55 @@ +/** + * 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. + */ + +it.each([[true, true], [true, true]])( + 'passes one row expected %s == %s', + (left, right) => { + expect(left).toBe(right); + } +); + +it.each([[true, true], [true, true]])( + 'passes all rows expected %s == %s', + (left, right) => { + expect(left).toBe(right); + } +); + +describe.each([[true, true], [true, true]])( + 'passes all rows expected %s == %s', + (left, right) => { + it('passes', () => { + expect(left).toBe(right); + }); + } +); + +it.each` + left | right + ${true} | ${true} + ${true} | ${true} +`('passes one row expected $left == $right', ({left, right}) => { + expect(left).toBe(right); +}); + +it.each` + left | right + ${true} | ${true} + ${true} | ${true} +`('passes all rows expected $left == $right', ({left, right}) => { + expect(left).toBe(right); +}); + +describe.each` + left | right + ${true} | ${true} + ${true} | ${true} +`('passes all rows expected $left == $right', ({left, right}) => { + it('passes ', () => { + expect(left).toBe(right); + }); +}); diff --git a/integration-tests/each/package.json b/integration-tests/each/package.json new file mode 100644 index 000000000000..148788b25446 --- /dev/null +++ b/integration-tests/each/package.json @@ -0,0 +1,5 @@ +{ + "jest": { + "testEnvironment": "node" + } +} diff --git a/packages/jest-jasmine2/src/__tests__/integration/each-only.test.js b/packages/jest-jasmine2/src/__tests__/integration/each-only.test.js deleted file mode 100644 index 0aeeba989d21..000000000000 --- a/packages/jest-jasmine2/src/__tests__/integration/each-only.test.js +++ /dev/null @@ -1,16 +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. - * - */ - -describe('.test.only.each', () => { - test.only.each([[0, 0, 0], [1, 1, 2], [5, 10, 15]])( - 'returns result of adding %s to %s', - (a, b, expected) => { - expect(a + b).toBe(expected); - }, - ); -}); diff --git a/packages/jest-jasmine2/src/__tests__/integration/each-skip.test.js b/packages/jest-jasmine2/src/__tests__/integration/each-skip.test.js deleted file mode 100644 index bcb84fe994c6..000000000000 --- a/packages/jest-jasmine2/src/__tests__/integration/each-skip.test.js +++ /dev/null @@ -1,16 +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. - * - */ - -describe('.test.skip.each', () => { - test.skip.each([[0, 0, 0], [1, 1, 2], [5, 10, 15]])( - 'returns result of adding %s to %s', - (a, b, expected) => { - expect(a + b).toBe(expected); - }, - ); -}); diff --git a/packages/jest-jasmine2/src/__tests__/integration/each.test.js b/packages/jest-jasmine2/src/__tests__/integration/each.test.js deleted file mode 100644 index b91ecf732761..000000000000 --- a/packages/jest-jasmine2/src/__tests__/integration/each.test.js +++ /dev/null @@ -1,77 +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. - * - */ - -describe('Data driven tests', () => { - describe('array table', () => { - describe('.test.each', () => { - test.each([[0, 0, 0], [1, 1, 2], [5, 10, 15]])( - 'returns result of adding %s to %s', - (a, b, expected) => { - expect(a + b).toBe(expected); - }, - ); - }); - - describe('.it.each', () => { - it.each([[0, 0, 0], [1, 1, 2], [5, 10, 15]])( - 'returns result of adding %s to %s', - (a, b, expected) => { - expect(a + b).toBe(expected); - }, - ); - }); - - describe('.describe.each', () => { - describe.each([[0, 0, 0], [1, 1, 2], [5, 10, 15]])( - '.add(%s, %s)', - (a, b, expected) => { - test(`returns ${expected}`, () => { - expect(a + b).toBe(expected); - }); - }, - ); - }); - }); - - describe('template literal table', () => { - describe('.test.each', () => { - test.each` - a | b | expected - ${0} | ${0} | ${0} - ${1} | ${1} | ${2} - ${5} | ${10} | ${15} - `('returns $expected when adding $a to $b', ({a, b, expected}) => { - expect(a + b).toBe(expected); - }); - }); - - describe('.it.each', () => { - it.each` - a | b | expected - ${0} | ${0} | ${0} - ${1} | ${1} | ${2} - ${5} | ${10} | ${15} - `('returns $expected when adding $a to $b', ({a, b, expected}) => { - expect(a + b).toBe(expected); - }); - }); - - describe('.describe.each', () => { - describe.each` - a | b | expected - ${0} | ${0} | ${0} - ${1} | ${1} | ${2} - ${5} | ${10} | ${15} - `('.add($a, $b)', ({a, b, expected}) => { - test(`returns ${expected}`, () => { - expect(a + b).toBe(expected); - }); - }); - }); - }); -});