Skip to content

Commit 0e574e6

Browse files
committed
add test for not clobbering entire object on error
1 parent 4d2477a commit 0e574e6

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()', () => {
@@ -469,6 +470,19 @@ describe('normalize()', () => {
469470
});
470471
});
471472

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

0 commit comments

Comments
 (0)