Skip to content
/ jest Public
forked from jestjs/jest

Commit

Permalink
fix: show stack traces on async assert errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Aug 9, 2018
1 parent d7eead1 commit 702b601
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- `[jest-snapshot]` Correctly merge property matchers with the rest of the snapshot in `toMatchSnapshot`. ([#6528](https://github.com/facebook/jest/pull/6528))
- `[jest-snapshot]` Add error messages for invalid property matchers. ([#6528](https://github.com/facebook/jest/pull/6528))
- `[jest-cli]` Show open handles from inside test files as well ([#6263](https://github.com/facebook/jest/pull/6263))
- `[jest-jasmine]` Show proper error message from async `assert` errors

### Chore & Maintenance

Expand Down
35 changes: 35 additions & 0 deletions e2e/__tests__/__snapshots__/failures.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ exports[`works with node assert 1`] = `
✕ assert.ifError
✕ assert.doesNotThrow
✕ assert.throws
✕ async
● assert
Expand Down Expand Up @@ -809,9 +810,43 @@ exports[`works with node assert 1`] = `
| ^
78 | });
79 |
80 | test('async', async () => {
at __tests__/node_assertion_error.test.js:77:10
async
Failed: \\"assert.equal(received, expected) or assert(received)
Expected value to be equal to:
\\\\\\"hello\\\\\\"
Received:
\\\\\\"hello
goodbye\\\\\\"
Message:
hmmm
Difference:
- Expected
+ Received
hello
+ goodbye
79 |
80 | test('async', async () => {
> 81 | assert.equal('hello\\\\ngoodbye', 'hello', 'hmmm');
| ^
82 | });
83 |
at __tests__/node_assertion_error.test.js:81:10
at __tests__/node_assertion_error.test.js:12:191
at __tests__/node_assertion_error.test.js:12:437
at __tests__/node_assertion_error.test.js:12:99
"
`;
Expand Down
4 changes: 4 additions & 0 deletions e2e/failures/__tests__/node_assertion_error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,7 @@ test('assert.doesNotThrow', () => {
test('assert.throws', () => {
assert.throws(() => {});
});

test('async', async () => {
assert.equal('hello\ngoodbye', 'hello', 'hmmm');
});
6 changes: 6 additions & 0 deletions packages/jest-jasmine2/src/jasmine/Env.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* eslint-disable sort-keys */

import {AssertionError} from 'assert';
import queueRunner from '../queue_runner';
import treeProcessor from '../tree_processor';
import checkIsError from '../is_error';
import assertionErrorMessage from '../assert_support';

// Try getting the real promise object from the context, if available. Someone
// could have overridden it in a test. Async functions return it implicitly.
Expand Down Expand Up @@ -547,6 +549,10 @@ export default function(j$) {
};

this.fail = function(error) {
if (error instanceof AssertionError) {
error = assertionErrorMessage(error, {expand: j$.Spec.expand});
}

const {isError, message} = checkIsError(error);

currentRunnable().addExpectationResult(false, {
Expand Down

0 comments on commit 702b601

Please sign in to comment.