Skip to content

Commit 760ca73

Browse files
committed
add test for not clobbering entire object on error
1 parent 777b710 commit 760ca73

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packages/utils/test/normalize.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import * as isModule from '../src/is';
66
import { normalize } from '../src/normalize';
7+
import * as stacktraceModule from '../src/stacktrace';
78
import { testOnlyIfNodeVersionAtLeast } from './testutils';
89

910
describe('normalize()', () => {
@@ -472,6 +473,19 @@ describe('normalize()', () => {
472473
});
473474
});
474475

476+
describe('handles serialization errors', () => {
477+
test('restricts effect of error to problematic node', () => {
478+
jest.spyOn(stacktraceModule, 'getFunctionName').mockImplementationOnce(() => {
479+
throw new Error('Nope');
480+
});
481+
482+
expect(normalize({ dogs: 'are great!', someFunc: () => {} })).toEqual({
483+
dogs: 'are great!',
484+
someFunc: '**non-serializable** (Error: Nope)',
485+
});
486+
});
487+
});
488+
475489
test('normalizes value on every iteration of decycle and takes care of things like Reacts SyntheticEvents', () => {
476490
const obj = {
477491
foo: {

0 commit comments

Comments
 (0)