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_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 new file mode 100644 index 000000000000..90532ebba079 --- /dev/null +++ b/e2e/jasmine-async/__tests__/pending_in_promise.test.js @@ -0,0 +1,6 @@ +'use strict'; + +it('skips a test inside a promise', () => + new Promise(() => { + pending('skipped a test inside a promise'); + })); diff --git a/packages/jest-jasmine2/src/jasmine_async.js b/packages/jest-jasmine2/src/jasmine_async.js index 1eaf0a8f2a4f..a45e9ac21c15 100644 --- a/packages/jest-jasmine2/src/jasmine_async.js +++ b/packages/jest-jasmine2/src/jasmine_async.js @@ -69,7 +69,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); @@ -102,7 +102,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(); @@ -146,8 +152,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);