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 3 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
7 changes: 7 additions & 0 deletions e2e/__tests__/jasmine_async.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 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,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

*/

'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