Skip to content

Commit 21e0f60

Browse files
authored
Update floating-point.spec.ts
1 parent 4b41bb9 commit 21e0f60

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

core/src/utils/floating-point/floating-point.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,24 @@ describe('floating point utils', () => {
1111
const n = getDecimalPlaces(5);
1212
expect(n).toBe(0);
1313
});
14+
15+
it('should handle nullish values', () => {
16+
expect(getDecimalPlaces(undefined as any)).toBe(0);
17+
expect(getDecimalPlaces(null as any)).toBe(0);
18+
expect(getDecimalPlaces(NaN as any)).toBe(0);
19+
});
1420
});
1521

1622
describe('roundToMaxDecimalPlaces', () => {
1723
it('should round to the highest number of places as references', async () => {
1824
const n = roundToMaxDecimalPlaces(5.12345, 1.12, 2.123);
1925
expect(n).toBe(5.123);
2026
});
27+
28+
it('should handle nullish values', () => {
29+
expect(roundToMaxDecimalPlaces(undefined as any)).toBe(0);
30+
expect(roundToMaxDecimalPlaces(null as any)).toBe(0);
31+
expect(roundToMaxDecimalPlaces(NaN as any)).toBe(0);
32+
})
2133
});
2234
});

0 commit comments

Comments
 (0)