-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Fix stack trace for errors thrown by snapshot serializers #4787
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
Changes from 1 commit
63e1795
d523a22
7c7069c
ee00b4e
c0d78a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
In this commit, we are creating a new custom error called `PrettyFormatPluginError`, this error is thrown by `prettyFormat` function when a serializer throws an error. In the `expect` module, we skip `Error.captureStackTrace` if the error name is `PrettyFormatPluginError`, this way the stack trace stays intact. Fixes #3302
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -549,6 +549,63 @@ describe('prettyFormat()', () => { | |
| }).toThrow(); | ||
| }); | ||
|
|
||
| it('throws PrettyFormatPluginError if test throws an error', () => { | ||
| const options = { | ||
| plugins: [ | ||
| { | ||
| print: () => '', | ||
| test() { | ||
| throw new Error('Where is the error?'); | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| try { | ||
| prettyFormat('', options); | ||
| } catch (error) { | ||
| expect(error.name).toBe('PrettyFormatPluginError'); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If for any reason the
let name;
try {
prettyFormat('', options);
} catch (error) {
name = error.name;
}
expect(name).toBe('PrettyFormatPluginError');
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either do
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SimenB Thank you! Because
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True. Or |
||
| }); | ||
|
|
||
| it('throws PrettyFormatPluginError if print throws an error', () => { | ||
| const options = { | ||
| plugins: [ | ||
| { | ||
| print: () => { | ||
| throw new Error('Where is the error?'); | ||
| }, | ||
| test: () => true, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| try { | ||
| prettyFormat('', options); | ||
| } catch (error) { | ||
| expect(error.name).toBe('PrettyFormatPluginError'); | ||
| } | ||
| }); | ||
|
|
||
| it('throws PrettyFormatPluginError if serialize throws an error', () => { | ||
| const options = { | ||
| plugins: [ | ||
| { | ||
| serialize: () => { | ||
| throw new Error('Where is the error?'); | ||
| }, | ||
| test: () => true, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| try { | ||
| prettyFormat('', options); | ||
| } catch (error) { | ||
| expect(error.name).toBe('PrettyFormatPluginError'); | ||
| } | ||
| }); | ||
|
|
||
| it('supports plugins with deeply nested arrays (#24)', () => { | ||
| const val = [[1, 2], [3, 4]]; | ||
| expect( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Triple equals?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing as the linter doesn't complain, maybe not needed