Skip to content
10 changes: 9 additions & 1 deletion packages/utils/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function visit(
// Get the simple cases out of the way first
if (
value == null || // this matches null and undefined -> eqeq not eqeqeq
(['number', 'boolean', 'string'].includes(typeof value) && !Number.isNaN(value))
(['number', 'boolean', 'string'].includes(typeof value) && Number.isFinite(value))
) {
return value as Primitive;
}
Expand Down Expand Up @@ -224,6 +224,14 @@ function stringifyValue(
return '[NaN]';
}

if (typeof value === 'number' && value === Infinity) {
return '[Infinity]';
}

if (typeof value === 'number' && value === -Infinity) {
return '[-Infinity]';
}

if (typeof value === 'function') {
return `[Function: ${getFunctionName(value)}]`;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/utils/test/normalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ describe('normalize()', () => {
describe('changes unserializeable/global values/classes to their respective string representations', () => {
test('primitive values', () => {
expect(normalize(NaN)).toEqual('[NaN]');
expect(normalize(Infinity)).toEqual('[Infinity]');
expect(normalize(-Infinity)).toEqual('[-Infinity]');
expect(normalize(Symbol('dogs'))).toEqual('[Symbol(dogs)]');
expect(normalize(BigInt(1121201212312012))).toEqual('[BigInt: 1121201212312012]');
});
Expand Down
Loading