forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap
Error.captureStackTrace
in a try (jestjs#4035)
* Wrap `Error.captureStackTrace` in a try Ref jestjs#4027 * Remove console.log * Add comment * Improve test * Readd assertion * Last assertion tweak
- Loading branch information
Showing
4 changed files
with
61 additions
and
4 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
integration_tests/__tests__/stack_trace_no_captureStackTrace.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
'use strict'; | ||
|
||
const runJest = require('../runJest'); | ||
|
||
describe('Stack Trace', () => { | ||
it('prints a usable stack trace even if no Error.captureStackTrace', () => { | ||
const result = runJest('stack_trace_no_captureStackTrace'); | ||
const stderr = result.stderr.toString(); | ||
|
||
const assertErrorLines = stderr.split('\n').slice(3, 9); | ||
|
||
expect(result.status).toBe(1); | ||
|
||
expect(stderr).toMatch(/\s+at\sJestAssertionError\s.*/); | ||
|
||
expect(assertErrorLines).toEqual([ | ||
' expect(received).toBe(expected)', | ||
' ', | ||
' Expected value to be (using ===):', | ||
' 2', | ||
' Received:', | ||
' 1', | ||
]); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
integration_tests/stack_trace_no_captureStackTrace/__tests__/runtime_error.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
'use strict'; | ||
|
||
Error.captureStackTrace = undefined; | ||
|
||
test('some test', () => { | ||
expect(1).toBe(2); | ||
}); |
5 changes: 5 additions & 0 deletions
5
integration_tests/stack_trace_no_captureStackTrace/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"jest": { | ||
"testEnvironment": "node" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters