-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent Error.captureStackTrace from erasing Error stack #5136
Comments
I would be happy to submit a PR that adds this functionality if there are no objections. 😄 |
We really should export Sorta related, if you know how to keep a stack across frames, help with #5104 would be appreciated :D |
Yeah, that would be even nicer. It just seemed (potentially) more controversial. I'd be happy to put together a PR for that instead. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I'm working on some custom Jest matchers for the React repo and I noticed a quirk that I believe is intentional, but doesn't seem optimal. Essentially the problem is this: I'm unable to throw an error from within a custom matcher without the stack being overridden by Jest via
Error.captureStackTrace
.So a meaningful stack like this:
Becomes a generic stack like this:
I'd like a way to preserve the original stack since it contains useful information. I don't object to the current default behavior, but it would be nice if there was a way to mark a specific error to be skipped. Looking at the source code though, it seems like there aren't really any good options:
JestAssertionError
(since the class isn't exposed externally).error.name
to "PrettyFormatPluginError" but this is a pretty major hack for a few reasons (it relies on undocumented internals and it would modify the error message logged to the developer).Error.captureStackTrace
, but this could not be done within the matcher; rather it would need to be done in a globalbeforeEach
hook.What would you think of an approach like the one React uses for error logging (eg a special property Jest checks for on an error like
dangerousDontCaptureStack
that prevents the stack from being overridden)?The text was updated successfully, but these errors were encountered: