-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not modify stack trace of JestAssertionError (#4516)
* Do not modify stack trace of JestAssertionError. * Added test for stack trace of nested matchers. * Fixed test for nested matcher and added test for normal matchers. * Only comparing line numbers in test because function names in stack trace seem to be platform dependent.
- Loading branch information
Showing
2 changed files
with
44 additions
and
4 deletions.
There are no files selected for viewing
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,38 @@ | ||
/** | ||
* 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. | ||
* | ||
*/ | ||
|
||
const jestExpect = require('../'); | ||
|
||
jestExpect.extend({ | ||
toMatchPredicate(received, argument) { | ||
argument(received); | ||
return { | ||
message: () => '', | ||
pass: true, | ||
}; | ||
}, | ||
}); | ||
|
||
it('stack trace points to correct location when using matchers', () => { | ||
try { | ||
jestExpect(true).toBe(false); | ||
} catch (error) { | ||
expect(error.stack).toContain('stacktrace.test.js:24'); | ||
} | ||
}); | ||
|
||
it('stack trace points to correct location when using nested matchers', () => { | ||
try { | ||
jestExpect(true).toMatchPredicate(value => { | ||
jestExpect(value).toBe(false); | ||
}); | ||
} catch (error) { | ||
expect(error.stack).toContain('stacktrace.test.js:33'); | ||
} | ||
}); |
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