Skip to content

Commit

Permalink
Fix/after all asserts bug (#5884)
Browse files Browse the repository at this point in the history
* Fixed the bug where mocking a file with the filename resolved as backticks would fail

* Updated changelog

* Added license info

* Fixed the unit test related to the backticks issue and updated the changelog with the PR link

* Update CHANGELOG.md

* Update CHANGELOG.md

* Added exception handling for when afterAll throws an Assert exception

* Added missing license

* Updated changelog

* Added assert to verify that the afterAll hook was the one failing

* Changed the test to check for thrown error in the afterAll hook
  • Loading branch information
rafaelramalho19 authored and cpojer committed Apr 9, 2018
1 parent c87fcf5 commit 89d98d3
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

### Fixes

* `[jest-jasmine2]` Added assertion error handling inside `afterAll hook`
([#5884](https://github.com/facebook/jest/pull/5884))
* `[jest-cli]` Remove the notifier actions in case of failure when not in watch
mode. ([#5861](https://github.com/facebook/jest/pull/5861))
* `[jest-mock]` Extend .toHaveBeenCalled return message with outcome
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

0 comments on commit 89d98d3

Please sign in to comment.