From 7ebace04472a3c59c89cb2c6b1e2d010c639882d Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 17 Apr 2018 18:17:56 +0200 Subject: [PATCH 1/2] fix stack-trace when calling `done` --- .../__tests__/__snapshots__/failures.test.js.snap | 12 +++++------- .../jest-jasmine2/src/expectation_result_factory.js | 3 ++- packages/jest-jasmine2/src/jasmine/Env.js | 1 + 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/integration-tests/__tests__/__snapshots__/failures.test.js.snap b/integration-tests/__tests__/__snapshots__/failures.test.js.snap index 852eed0e2a00..a526c9e1ef82 100644 --- a/integration-tests/__tests__/__snapshots__/failures.test.js.snap +++ b/integration-tests/__tests__/__snapshots__/failures.test.js.snap @@ -240,17 +240,15 @@ exports[`not throwing Error objects 5`] = ` ], } - 33 | }); 34 | - > 35 | test('done(non-error)', done => { - | ^ - 36 | done(deepObject); + 35 | test('done(non-error)', done => { + > 36 | done(deepObject); + | ^ 37 | }); 38 | - - at packages/jest-jasmine2/build/jasmine/Spec.js:79:20 - at __tests__/during_tests.test.js:35:1 + at packages/jest-jasmine2/build/expectation_result_factory.js:62:10 + at __tests__/during_tests.test.js:36:3 " `; diff --git a/packages/jest-jasmine2/src/expectation_result_factory.js b/packages/jest-jasmine2/src/expectation_result_factory.js index 32e04989a969..45163c7768a3 100644 --- a/packages/jest-jasmine2/src/expectation_result_factory.js +++ b/packages/jest-jasmine2/src/expectation_result_factory.js @@ -40,7 +40,7 @@ function stackFormatter(options, initError, errorMessage) { return options.error.stack; } - if (initError) { + if (!options.fromFail && initError) { return errorMessage + '\n' + initError.stack; } @@ -50,6 +50,7 @@ function stackFormatter(options, initError, errorMessage) { type Options = { matcherName: string, passed: boolean, + fromFail?: boolean, actual?: any, error?: any, expected?: any, diff --git a/packages/jest-jasmine2/src/jasmine/Env.js b/packages/jest-jasmine2/src/jasmine/Env.js index 6adaab2e8113..e4c658ad51f7 100644 --- a/packages/jest-jasmine2/src/jasmine/Env.js +++ b/packages/jest-jasmine2/src/jasmine/Env.js @@ -561,6 +561,7 @@ export default function(j$) { expected: '', actual: '', message, + fromFail: true, error: isError ? error : null, }); }; From ebcf9f0e1f39c38e6a6903d9fe5c6c219ac7a19a Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 17 Apr 2018 18:21:13 +0200 Subject: [PATCH 2/2] create Error in `fail` if not passed --- .../__tests__/__snapshots__/failures.test.js.snap | 2 +- packages/jest-jasmine2/src/expectation_result_factory.js | 3 +-- packages/jest-jasmine2/src/jasmine/Env.js | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/integration-tests/__tests__/__snapshots__/failures.test.js.snap b/integration-tests/__tests__/__snapshots__/failures.test.js.snap index a526c9e1ef82..9a242729b6c8 100644 --- a/integration-tests/__tests__/__snapshots__/failures.test.js.snap +++ b/integration-tests/__tests__/__snapshots__/failures.test.js.snap @@ -247,7 +247,7 @@ exports[`not throwing Error objects 5`] = ` 37 | }); 38 | - at packages/jest-jasmine2/build/expectation_result_factory.js:62:10 + at packages/jest-jasmine2/build/jasmine/Env.js:542:34 at __tests__/during_tests.test.js:36:3 " diff --git a/packages/jest-jasmine2/src/expectation_result_factory.js b/packages/jest-jasmine2/src/expectation_result_factory.js index 45163c7768a3..32e04989a969 100644 --- a/packages/jest-jasmine2/src/expectation_result_factory.js +++ b/packages/jest-jasmine2/src/expectation_result_factory.js @@ -40,7 +40,7 @@ function stackFormatter(options, initError, errorMessage) { return options.error.stack; } - if (!options.fromFail && initError) { + if (initError) { return errorMessage + '\n' + initError.stack; } @@ -50,7 +50,6 @@ function stackFormatter(options, initError, errorMessage) { type Options = { matcherName: string, passed: boolean, - fromFail?: boolean, actual?: any, error?: any, expected?: any, diff --git a/packages/jest-jasmine2/src/jasmine/Env.js b/packages/jest-jasmine2/src/jasmine/Env.js index e4c658ad51f7..f73c1745065b 100644 --- a/packages/jest-jasmine2/src/jasmine/Env.js +++ b/packages/jest-jasmine2/src/jasmine/Env.js @@ -561,8 +561,7 @@ export default function(j$) { expected: '', actual: '', message, - fromFail: true, - error: isError ? error : null, + error: isError ? error : new Error(message), }); }; }