From dd386f86a65525c5da392e7acc3df68ac9e957e5 Mon Sep 17 00:00:00 2001 From: VolodymyrBg Date: Fri, 17 Jan 2025 20:41:04 +0200 Subject: [PATCH] Update bn.test.ts --- packages/math/src/bn.test.ts | 50 +++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/packages/math/src/bn.test.ts b/packages/math/src/bn.test.ts index 830b695d468..449f6419221 100644 --- a/packages/math/src/bn.test.ts +++ b/packages/math/src/bn.test.ts @@ -542,26 +542,34 @@ describe('Math - BN', () => { expect(bn('4000000').format({ precision: 1 })).toEqual('0.004'); }); - it('should warn when precision is less than minPrecision', () => { - const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(); - - // Test case where precision < minPrecision - bn(123).format({ precision: 2, minPrecision: 4 }); - - expect(consoleWarnSpy).toHaveBeenCalledWith( - 'Warning: precision (2) is less than minPrecision (4). ' + - 'This may lead to unexpected behavior. Consider setting precision >= minPrecision.' - ); - - // Test case where precision = minPrecision (should not warn) - consoleWarnSpy.mockClear(); - bn(123).format({ precision: 4, minPrecision: 4 }); - expect(consoleWarnSpy).not.toHaveBeenCalled(); - - // Test case where precision > minPrecision (should not warn) - bn(123).format({ precision: 6, minPrecision: 4 }); - expect(consoleWarnSpy).not.toHaveBeenCalled(); - - consoleWarnSpy.mockRestore(); + describe('precision validation', () => { + let consoleWarnSpy: jest.SpyInstance; + + beforeEach(() => { + consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(); + }); + + afterEach(() => { + consoleWarnSpy.mockRestore(); + }); + + it('should warn when precision is less than minPrecision', () => { + bn(123).format({ precision: 2, minPrecision: 4 }); + + expect(consoleWarnSpy).toHaveBeenCalledWith( + 'Warning: precision (2) is less than minPrecision (4). ' + + 'This may lead to unexpected behavior. Consider setting precision >= minPrecision.' + ); + }); + + it('should not warn when precision equals minPrecision', () => { + bn(123).format({ precision: 4, minPrecision: 4 }); + expect(consoleWarnSpy).not.toHaveBeenCalled(); + }); + + it('should not warn when precision is greater than minPrecision', () => { + bn(123).format({ precision: 6, minPrecision: 4 }); + expect(consoleWarnSpy).not.toHaveBeenCalled(); + }); }); });