Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added exception handling for when afterAll throws an Assert exception
  • Loading branch information
rafaelramalho19 committed Mar 27, 2018
commit c78c05d7e0d1f92a9ffa6d1975c28e9110ae2db7
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(/FAIL/);
Copy link
Member

Choose a reason for hiding this comment

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

can you assert that the original error is in here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure :)

});
5 changes: 5 additions & 0 deletions integration-tests/lifecycles/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
afterAll(() => {
expect(1).toBe(2);
});
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