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

Fix/after all asserts bug #5884

Merged
merged 16 commits into from
Apr 9, 2018
Merged
Show file tree
Hide file tree
Changes from 15 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

### Fixes

* `[jest-jasmine2]` Added assertion error handling inside `afterAll hook`
([#5884](https://github.com/facebook/jest/pull/5884))
* `[jest-runner]` Assign `process.env.JEST_WORKER_ID="1"` when in runInBand mode
([#5860](https://github.com/facebook/jest/pull/5860))
* `[jest-cli]` Add descriptive error message when trying to use
Expand Down
18 changes: 18 additions & 0 deletions integration-tests/__tests__/lifecycles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* 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.
*
* @flow
*/
'use strict';

const runJest = require('../runJest');

test('suite with invalid assertions in afterAll', () => {
const {stderr, status} = runJest('lifecycles');

expect(status).toBe(1);
expect(stderr).toMatch(/afterAll just failed!/);
});
12 changes: 12 additions & 0 deletions integration-tests/lifecycles/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* 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.
*/

afterAll(() => {
throw new Error('afterAll just failed!');
});
test('one', () => {});
test('two', () => {});
9 changes: 9 additions & 0 deletions integration-tests/lifecycles/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* 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.
*
*/

module.exports = () => {};
5 changes: 5 additions & 0 deletions integration-tests/lifecycles/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"jest": {
"testEnvironment": "node"
}
}
7 changes: 7 additions & 0 deletions packages/jest-jasmine2/src/jasmine/js_api_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ export default function JsApiReporter(options: Object) {

let executionTime;

function validateAfterAllExceptions({failedExpectations}) {
if (failedExpectations && failedExpectations.length > 0) {
throw failedExpectations[0];
}
}

this.jasmineDone = function(runDetails) {
validateAfterAllExceptions(runDetails);
this.finished = true;
this.runDetails = runDetails;
executionTime = timer.elapsed();
Expand Down