Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling pending calls inside async tests properly. #6782

Merged
merged 4 commits into from
Oct 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
20 changes: 20 additions & 0 deletions e2e/__tests__/jasmine_async_with_pending_during_test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
6 changes: 6 additions & 0 deletions e2e/jasmine-async/__tests__/pending_in_promise.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

it('skips a test inside a promise', () =>
new Promise(() => {
pending('skipped a test inside a promise');
}));
14 changes: 10 additions & 4 deletions packages/jest-jasmine2/src/jasmine_async.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down