From e06cea43e6b608eb42397450d4ab11672da7222a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Baris=20Gu=CC=88mu=CC=88stas?= Date: Mon, 30 Jul 2018 17:25:53 +0200 Subject: [PATCH 1/3] Handling pending calls inside async tests properly. --- packages/jest-jasmine2/src/jasmine_async.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/jest-jasmine2/src/jasmine_async.js b/packages/jest-jasmine2/src/jasmine_async.js index 01b5ec27e87d..61c9636393b5 100644 --- a/packages/jest-jasmine2/src/jasmine_async.js +++ b/packages/jest-jasmine2/src/jasmine_async.js @@ -63,7 +63,7 @@ function promisifyLifeCycleFunction(originalFn, env) { // Similar to promisifyLifeCycleFunction but throws an error // when the return value is neither a Promise nor `undefined` -function promisifyIt(originalFn, env) { +function promisifyIt(originalFn, env, jasmine) { return function(specName, fn, timeout) { if (!fn) { const spec = originalFn.call(env, specName); @@ -90,7 +90,13 @@ function promisifyIt(originalFn, env) { if (message) { extraError.message = message; } - done.fail(isError ? error : extraError); + + if (jasmine.Spec.isPendingSpecException(error)) { + env.pending(message); + done(); + } else { + done.fail(isError ? error : extraError); + } }); } else if (returnValue === undefined) { done(); @@ -134,8 +140,8 @@ export function install(global: Global) { const jasmine = global.jasmine; const env = jasmine.getEnv(); - env.it = promisifyIt(env.it, env); - env.fit = promisifyIt(env.fit, env); + env.it = promisifyIt(env.it, env, jasmine); + env.fit = promisifyIt(env.fit, env, jasmine); global.it.concurrent = makeConcurrent(env.it, env); global.it.concurrent.only = makeConcurrent(env.fit, env); global.it.concurrent.skip = makeConcurrent(env.xit, env); From 469e549af2ef139379a39242301a7191c1606fb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Baris=20Gu=CC=88mu=CC=88stas?= Date: Mon, 8 Oct 2018 11:46:15 +0200 Subject: [PATCH 2/3] Added e2e tests and a changelog entry for handling of pending calls in async tests. --- CHANGELOG.md | 1 + e2e/__tests__/jasmine_async.test.js | 7 +++++++ .../__tests__/pending_in_promise.test.js | 15 +++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 e2e/jasmine-async/__tests__/pending_in_promise.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 28fc48be6596..cac33660b742 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ - `[jest-circus]` Fail synchronous hook timeouts ([#7074](https://github.com/facebook/jest/pull/7074)) - `[jest-jasmine2]` Fail synchronous test timeouts ([#7074](https://github.com/facebook/jest/pull/7074)) - `[jest-jasmine2]` Better error message when a describe block is empty ([#6372](https://github.com/facebook/jest/pull/6372)) +- `[jest-jasmine2]` Pending calls inside async tests are reported as pending not failed ([#6782](https://github.com/facebook/jest/pull/6782)) - `[jest-circus]` Better error message when a describe block is empty ([#6372](https://github.com/facebook/jest/pull/6372)) - `[jest-cli]` Fix unhandled error when a bad revision is provided to `changedSince` ([#7115](https://github.com/facebook/jest/pull/7115)) diff --git a/e2e/__tests__/jasmine_async.test.js b/e2e/__tests__/jasmine_async.test.js index 1ba352637969..4e5de1f97776 100644 --- a/e2e/__tests__/jasmine_async.test.js +++ b/e2e/__tests__/jasmine_async.test.js @@ -119,6 +119,13 @@ describe('async jasmine', () => { expect(message).toMatch('fails if a custom timeout is exceeded'); }); + it('tests async promise when it skips during the test', () => { + const result = runWithJson('jasmine-async', ['pending_in_promise.test.js']); + const json = result.json; + + expect(json.numPendingTests).toBe(1); + }); + it('works with concurrent', () => { const result = runWithJson('jasmine-async', ['concurrent.test.js']); const json = result.json; diff --git a/e2e/jasmine-async/__tests__/pending_in_promise.test.js b/e2e/jasmine-async/__tests__/pending_in_promise.test.js new file mode 100644 index 000000000000..2729f1f5285a --- /dev/null +++ b/e2e/jasmine-async/__tests__/pending_in_promise.test.js @@ -0,0 +1,15 @@ +/** + * Copyright (c) 2014-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. + * + * @jest-environment jsdom + */ + +'use strict'; + +it('skips a test inside a promise', () => + new Promise(() => { + pending('skipped a test inside a promise'); + })); From f44002056a47e3ef924462710caf3849092cc143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Baris=20Gu=CC=88mu=CC=88stas?= Date: Mon, 8 Oct 2018 13:54:42 +0200 Subject: [PATCH 3/3] Skipping the e2e "jasmine pending during test" test for circus. --- e2e/__tests__/jasmine_async.test.js | 7 ------- .../jasmine_async_with_pending_during_test.js | 20 +++++++++++++++++++ .../__tests__/pending_in_promise.test.js | 9 --------- 3 files changed, 20 insertions(+), 16 deletions(-) create mode 100644 e2e/__tests__/jasmine_async_with_pending_during_test.js diff --git a/e2e/__tests__/jasmine_async.test.js b/e2e/__tests__/jasmine_async.test.js index 4e5de1f97776..1ba352637969 100644 --- a/e2e/__tests__/jasmine_async.test.js +++ b/e2e/__tests__/jasmine_async.test.js @@ -119,13 +119,6 @@ describe('async jasmine', () => { expect(message).toMatch('fails if a custom timeout is exceeded'); }); - it('tests async promise when it skips during the test', () => { - const result = runWithJson('jasmine-async', ['pending_in_promise.test.js']); - const json = result.json; - - expect(json.numPendingTests).toBe(1); - }); - it('works with concurrent', () => { const result = runWithJson('jasmine-async', ['concurrent.test.js']); const json = result.json; diff --git a/e2e/__tests__/jasmine_async_with_pending_during_test.js b/e2e/__tests__/jasmine_async_with_pending_during_test.js new file mode 100644 index 000000000000..b93f79598bfb --- /dev/null +++ b/e2e/__tests__/jasmine_async_with_pending_during_test.js @@ -0,0 +1,20 @@ +/* @flow */ + +'use strict'; + +import {json as runWithJson} from '../runJest'; +import {skipSuiteOnJestCircus} from '../../scripts/ConditionalTest'; + +describe('async jasmine with pending during test', () => { + skipSuiteOnJestCircus(); + + it('should be reported as a pending test', () => { + const result = runWithJson('jasmine-async', ['pending_in_promise.test.js']); + const json = result.json; + + expect(json.numTotalTests).toBe(1); + expect(json.numPassedTests).toBe(0); + expect(json.numFailedTests).toBe(0); + expect(json.numPendingTests).toBe(1); + }); +}); diff --git a/e2e/jasmine-async/__tests__/pending_in_promise.test.js b/e2e/jasmine-async/__tests__/pending_in_promise.test.js index 2729f1f5285a..90532ebba079 100644 --- a/e2e/jasmine-async/__tests__/pending_in_promise.test.js +++ b/e2e/jasmine-async/__tests__/pending_in_promise.test.js @@ -1,12 +1,3 @@ -/** - * Copyright (c) 2014-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. - * - * @jest-environment jsdom - */ - 'use strict'; it('skips a test inside a promise', () =>