diff --git a/front/src/utils/__tests__/cast-as-positive-integer-or-null.test.ts b/front/src/utils/__tests__/cast-as-positive-integer-or-null.test.ts index 1c3e9d10b..b9a88647c 100644 --- a/front/src/utils/__tests__/cast-as-positive-integer-or-null.test.ts +++ b/front/src/utils/__tests__/cast-as-positive-integer-or-null.test.ts @@ -16,12 +16,12 @@ describe('canBeCastAsPositiveIntegerOrNull', () => { expect(canBeCastAsPositiveIntegerOrNull(-9)).toBeFalsy(); }); - it(`should return false if zero`, () => { - expect(canBeCastAsPositiveIntegerOrNull(0)).toBeFalsy(); + it(`should return true if zero`, () => { + expect(canBeCastAsPositiveIntegerOrNull(0)).toBeTruthy(); }); - it(`should return false if string 0`, () => { - expect(canBeCastAsPositiveIntegerOrNull('0')).toBeFalsy(); + it(`should return true if string 0`, () => { + expect(canBeCastAsPositiveIntegerOrNull('0')).toBeTruthy(); }); it(`should return false if negative float`, () => { @@ -82,12 +82,12 @@ describe('castAsPositiveIntegerOrNull', () => { expect(castAsPositiveIntegerOrNull('9')).toBe(9); }); - it(`should throw if trying to cast a 0 to positive integer`, () => { - expect(() => castAsPositiveIntegerOrNull(0)).toThrow(Error); + it(`should cast an integer to zero integer`, () => { + expect(castAsPositiveIntegerOrNull(0)).toBe(0); }); - it(`should throw if trying to cast a string 0 to positive integer`, () => { - expect(() => castAsPositiveIntegerOrNull('0')).toThrow(Error); + it(`should cast an integer string to zero integer`, () => { + expect(castAsPositiveIntegerOrNull('0')).toBe(0); }); it(`should throw if trying to cast a positive float string to positive integer`, () => { diff --git a/front/src/utils/cast-as-positive-integer-or-null.ts b/front/src/utils/cast-as-positive-integer-or-null.ts index 56ad707fe..1751fd4a3 100644 --- a/front/src/utils/cast-as-positive-integer-or-null.ts +++ b/front/src/utils/cast-as-positive-integer-or-null.ts @@ -8,7 +8,7 @@ export function canBeCastAsPositiveIntegerOrNull( if (typeof probablePositiveNumberOrNull === 'number') { return ( Number.isInteger(probablePositiveNumberOrNull) && - Math.sign(probablePositiveNumberOrNull) === 1 + Math.sign(probablePositiveNumberOrNull) !== -1 ); } @@ -27,7 +27,7 @@ export function canBeCastAsPositiveIntegerOrNull( return false; } - if (Number.isInteger(stringAsNumber) && Math.sign(stringAsNumber) === 1) { + if (Number.isInteger(stringAsNumber) && Math.sign(stringAsNumber) !== -1) { return true; } }