diff --git a/.eslintrc.js b/.eslintrc.js index c842db401..6851d9566 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -81,6 +81,7 @@ module.exports = { files: [ 'app/**/*.js', 'shared/**/*.js', + 'shared/**/*.ts', 'ui/**/*.js', '**/*.test.js', 'test/lib/**/*.js', @@ -272,6 +273,7 @@ module.exports = { 'app/scripts/platforms/*.test.js', 'development/**/*.test.js', 'shared/**/*.test.js', + 'shared/**/*.test.ts', 'test/helpers/*.js', 'test/jest/*.js', 'ui/**/*.test.js', diff --git a/shared/modules/Numeric.test.ts b/shared/modules/Numeric.test.ts index 2786bec91..33e8f4ee2 100644 --- a/shared/modules/Numeric.test.ts +++ b/shared/modules/Numeric.test.ts @@ -10,98 +10,98 @@ const ONE_WEI = new Numeric(1, 10, EtherDenomination.WEI); describe('Numeric', () => { describe('Basic Numeric Construction', () => { describe('From hexadeciaml strings', () => { - it('Should create a new Numeric from a hexadecimal string', () => { + it('should create a new Numeric from a hexadecimal string', () => { const numeric = new Numeric('0xa', 16); - expect(numeric.value).toEqual(new BigNumber(10, 10)); + expect(numeric.value).toStrictEqual(new BigNumber(10, 10)); }); - it('Should create a new Numeric from a hexadecimal string with a decimal', () => { + it('should create a new Numeric from a hexadecimal string with a decimal', () => { const numeric = new Numeric('0xa.7', 16); - expect(numeric.value).toEqual(new BigNumber(10.4375, 10)); + expect(numeric.value).toStrictEqual(new BigNumber(10.4375, 10)); }); - it('Should create a new Numeric from a hexadecimal string with negation', () => { + it('should create a new Numeric from a hexadecimal string with negation', () => { const numeric = new Numeric('-0xa', 16); - expect(numeric.value).toEqual(new BigNumber(-10, 10)); + expect(numeric.value).toStrictEqual(new BigNumber(-10, 10)); }); - it('Should create a new Numeric from a hexadecimal string with negation and decimal', () => { + it('should create a new Numeric from a hexadecimal string with negation and decimal', () => { const numeric = new Numeric('-0xa.7', 16); - expect(numeric.value).toEqual(new BigNumber(-10.4375, 10)); + expect(numeric.value).toStrictEqual(new BigNumber(-10.4375, 10)); }); }); describe('From decimal strings', () => { - it('Should create a new Numeric from a decimal string', () => { + it('should create a new Numeric from a decimal string', () => { const numeric = new Numeric('10', 10); - expect(numeric.value).toEqual(new BigNumber(10, 10)); + expect(numeric.value).toStrictEqual(new BigNumber(10, 10)); }); - it('Should create a new Numeric from a decimal string with a decimal', () => { + it('should create a new Numeric from a decimal string with a decimal', () => { const numeric = new Numeric('10.4375', 10); - expect(numeric.value).toEqual(new BigNumber(10.4375, 10)); + expect(numeric.value).toStrictEqual(new BigNumber(10.4375, 10)); }); - it('Should create a new Numeric from a decimal string with negation', () => { + it('should create a new Numeric from a decimal string with negation', () => { const numeric = new Numeric('-10', 10); - expect(numeric.value).toEqual(new BigNumber(-10, 10)); + expect(numeric.value).toStrictEqual(new BigNumber(-10, 10)); }); - it('Should create a new Numeric from a decimal string with negation and decimal', () => { + it('should create a new Numeric from a decimal string with negation and decimal', () => { const numeric = new Numeric('-10.4375', 10); - expect(numeric.value).toEqual(new BigNumber(-10.4375, 10)); + expect(numeric.value).toStrictEqual(new BigNumber(-10.4375, 10)); }); }); describe('From decimal numbers', () => { - it('Should create a new Numeric from a hexadecimal number', () => { + it('should create a new Numeric from a hexadecimal number', () => { const numeric = new Numeric(10, 10); - expect(numeric.value).toEqual(new BigNumber(10, 10)); + expect(numeric.value).toStrictEqual(new BigNumber(10, 10)); }); - it('Should create a new Numeric from a hexadecimal string with a decimal', () => { + it('should create a new Numeric from a hexadecimal string with a decimal', () => { const numeric = new Numeric(10.4375, 10); - expect(numeric.value).toEqual(new BigNumber(10.4375, 10)); + expect(numeric.value).toStrictEqual(new BigNumber(10.4375, 10)); }); - it('Should create a new Numeric from a hexadecimal string with negation', () => { + it('should create a new Numeric from a hexadecimal string with negation', () => { const numeric = new Numeric(-10, 10); - expect(numeric.value).toEqual(new BigNumber(-10, 10)); + expect(numeric.value).toStrictEqual(new BigNumber(-10, 10)); }); - it('Should create a new Numeric from a hexadecimal string with negation and decimal', () => { + it('should create a new Numeric from a hexadecimal string with negation and decimal', () => { const numeric = new Numeric(-10.4375, 16); - expect(numeric.value).toEqual(new BigNumber(-10.4375, 10)); + expect(numeric.value).toStrictEqual(new BigNumber(-10.4375, 10)); }); }); describe('From BigNumbers or BN', () => { - it('Should create a new Numeric from a BigNumber', () => { + it('should create a new Numeric from a BigNumber', () => { const numeric = new Numeric(new BigNumber(100, 10)); - expect(numeric.value).toEqual(new BigNumber(100, 10)); + expect(numeric.value).toStrictEqual(new BigNumber(100, 10)); }); - it('Should create a new Numeric from a BN', () => { + it('should create a new Numeric from a BN', () => { const numeric = new Numeric(new BN(100, 10), 10); - expect(numeric.value).toEqual(new BigNumber(100, 10)); + expect(numeric.value).toStrictEqual(new BigNumber(100, 10)); }); }); }); describe('Error checking', () => { - it('Should throw an error for a non numeric string', () => { + it('should throw an error for a non numeric string', () => { expect(() => new Numeric('Hello there', 10)).toThrow( 'String provided to stringToBigNumber is not a hexadecimal or decimal string: Hello there, 10', ); }); - it('Should throw an error for a numeric string without a base', () => { + it('should throw an error for a numeric string without a base', () => { expect(() => new Numeric('10')).toThrow( 'You must specify the base of the provided number if the value is not already a BigNumber', ); }); - it('Should throw an error for a non numeric type', () => { + it('should throw an error for a non numeric type', () => { expect(() => new Numeric(true as unknown as number, 10)).toThrow( 'Value: true is not a string, number, BigNumber or BN. Type is: boolean.', ); @@ -109,454 +109,474 @@ describe('Numeric', () => { }); describe('Erroneous behaviors that we are temporarily continuing', () => { - it('Handles values that are undefined, setting the value to 0', () => { - expect(new Numeric(undefined as unknown as number).toString()).toEqual( - '0', - ); + it('handles values that are undefined, setting the value to 0', () => { + expect( + new Numeric(undefined as unknown as number).toString(), + ).toStrictEqual('0'); }); - it('Handles values that are NaN, setting the value to 0', () => { - expect(new Numeric(NaN).toString()).toEqual('0'); + it('handles values that are NaN, setting the value to 0', () => { + expect(new Numeric(NaN).toString()).toStrictEqual('0'); }); }); describe('Ether denomination conversion', () => { it('should convert 1 ETH to 1000000000 GWEI', () => { - expect(ONE_ETH.toDenomination(EtherDenomination.GWEI).toString()).toEqual( - '1000000000', - ); + expect( + ONE_ETH.toDenomination(EtherDenomination.GWEI).toString(), + ).toStrictEqual('1000000000'); }); it('should convert 1 ETH to 1000000000000000000 WEI', () => { - expect(ONE_ETH.toDenomination(EtherDenomination.WEI).toString()).toEqual( - '1000000000000000000', - ); + expect( + ONE_ETH.toDenomination(EtherDenomination.WEI).toString(), + ).toStrictEqual('1000000000000000000'); }); it('should convert 1 GWEI to 0.000000001 ETH', () => { - expect(ONE_GWEI.toDenomination(EtherDenomination.ETH).toString()).toEqual( - '0.000000001', - ); + expect( + ONE_GWEI.toDenomination(EtherDenomination.ETH).toString(), + ).toStrictEqual('0.000000001'); }); it('should convert 1 GWEI to 1000000000 WEI', () => { - expect(ONE_GWEI.toDenomination(EtherDenomination.WEI).toString()).toEqual( - '1000000000', - ); + expect( + ONE_GWEI.toDenomination(EtherDenomination.WEI).toString(), + ).toStrictEqual('1000000000'); }); it('should convert 1 WEI to 0 ETH due to rounding', () => { - expect(ONE_WEI.toDenomination(EtherDenomination.ETH).toString()).toEqual( - '0', - ); + expect( + ONE_WEI.toDenomination(EtherDenomination.ETH).toString(), + ).toStrictEqual('0'); }); it('should convert 1 WEI to 0.000000001 GWEI', () => { - expect(ONE_WEI.toDenomination(EtherDenomination.GWEI).toString()).toEqual( - '0.000000001', - ); + expect( + ONE_WEI.toDenomination(EtherDenomination.GWEI).toString(), + ).toStrictEqual('0.000000001'); }); }); describe('Math operations', () => { describe('Multiplication', () => { - it('Should compute correct results for simple multiplication', () => { - expect(new Numeric(5, 10).times(5, 10).toNumber()).toEqual(25); + it('should compute correct results for simple multiplication', () => { + expect(new Numeric(5, 10).times(5, 10).toNumber()).toStrictEqual(25); expect( new Numeric(5, 10).times(new Numeric(10, 10)).toNumber(), - ).toEqual(50); + ).toStrictEqual(50); expect( new Numeric(25, 10).times(new Numeric(10, 10)).toNumber(), - ).toEqual(250); + ).toStrictEqual(250); }); - it('Should compute correct results for multiplication of big numbers', () => { + it('should compute correct results for multiplication of big numbers', () => { expect( new Numeric('175671432', 10).times('686216', 10).toString(), - ).toEqual('120548547381312'); + ).toStrictEqual('120548547381312'); expect( new Numeric('1756714320', 10) .times(new Numeric('686216', 10)) .toString(), - ).toEqual('1205485473813120'); + ).toStrictEqual('1205485473813120'); expect( new Numeric('41756714320', 10) .times(new Numeric('6862160', 10)) .toString(), - ).toEqual('286541254738131200'); + ).toStrictEqual('286541254738131200'); }); - it('Should compute correct results for multiplication of negative big numbers', () => { + it('should compute correct results for multiplication of negative big numbers', () => { expect( new Numeric('175671432', 10).times('-686216', 10).toString(), - ).toEqual('-120548547381312'); + ).toStrictEqual('-120548547381312'); expect( new Numeric('1756714320', 10) .times(new Numeric('-686216', 10)) .toString(), - ).toEqual('-1205485473813120'); + ).toStrictEqual('-1205485473813120'); expect( new Numeric('-41756714320', 10) .times(new Numeric('-6862160', 10)) .toString(), - ).toEqual('286541254738131200'); + ).toStrictEqual('286541254738131200'); }); }); describe('Division', () => { - it('Should compute correct results for simple division', () => { - expect(new Numeric(25, 10).divide(5, 10).toNumber()).toEqual(5); + it('should compute correct results for simple division', () => { + expect(new Numeric(25, 10).divide(5, 10).toNumber()).toStrictEqual(5); expect( new Numeric(50, 10).divide(new Numeric(10, 10)).toNumber(), - ).toEqual(5); + ).toStrictEqual(5); expect( new Numeric(250, 10).divide(new Numeric(10, 10)).toNumber(), - ).toEqual(25); + ).toStrictEqual(25); }); - it('Should compute correct results for division of big numbers', () => { + it('should compute correct results for division of big numbers', () => { expect( new Numeric('175671432', 10).divide('686216', 10).toString(), - ).toEqual('256.00019818832554181191'); + ).toStrictEqual('256.00019818832554181191'); expect( new Numeric('1756714320', 10) .divide(new Numeric('686216', 10)) .toString(), - ).toEqual('2560.00198188325541811908'); + ).toStrictEqual('2560.00198188325541811908'); expect( new Numeric('41756714320', 10) .divide(new Numeric('6862160', 10)) .toString(), - ).toEqual('6085.06859647691106007438'); + ).toStrictEqual('6085.06859647691106007438'); }); - it('Should compute correct results for division of negative big numbers', () => { + it('should compute correct results for division of negative big numbers', () => { expect( new Numeric('175671432', 10).divide('-686216', 10).toString(), - ).toEqual('-256.00019818832554181191'); + ).toStrictEqual('-256.00019818832554181191'); expect( new Numeric('1756714320', 10) .divide(new Numeric('-686216', 10)) .toString(), - ).toEqual('-2560.00198188325541811908'); + ).toStrictEqual('-2560.00198188325541811908'); expect( new Numeric('-41756714320', 10) .divide(new Numeric('-6862160', 10)) .toString(), - ).toEqual('6085.06859647691106007438'); + ).toStrictEqual('6085.06859647691106007438'); }); }); describe('Addition', () => { - it('Should compute correct results for simple addition', () => { - expect(new Numeric(25, 10).add(5, 10).toNumber()).toEqual(30); + it('should compute correct results for simple addition', () => { + expect(new Numeric(25, 10).add(5, 10).toNumber()).toStrictEqual(30); - expect(new Numeric(50, 10).add(new Numeric(10, 10)).toNumber()).toEqual( - 60, - ); + expect( + new Numeric(50, 10).add(new Numeric(10, 10)).toNumber(), + ).toStrictEqual(60); expect( new Numeric(250, 10).add(new Numeric(100, 10)).toNumber(), - ).toEqual(350); + ).toStrictEqual(350); }); - it('Should compute correct results for addition of big numbers', () => { + it('should compute correct results for addition of big numbers', () => { expect( new Numeric('175671432', 10).add('686216', 10).toString(), - ).toEqual('176357648'); + ).toStrictEqual('176357648'); expect( new Numeric('1756714320', 10) .add(new Numeric('686216', 10)) .toString(), - ).toEqual('1757400536'); + ).toStrictEqual('1757400536'); expect( new Numeric('41756714320', 10) .add(new Numeric('6862160', 10)) .toString(), - ).toEqual('41763576480'); + ).toStrictEqual('41763576480'); }); - it('Should compute correct results for addition of negative big numbers', () => { + it('should compute correct results for addition of negative big numbers', () => { expect( new Numeric('175671432', 10).add('-686216', 10).toString(), - ).toEqual('174985216'); + ).toStrictEqual('174985216'); expect( new Numeric('1756714320', 10) .add(new Numeric('-686216', 10)) .toString(), - ).toEqual('1756028104'); + ).toStrictEqual('1756028104'); expect( new Numeric('-41756714320', 10) .add(new Numeric('-6862160', 10)) .toString(), - ).toEqual('-41763576480'); + ).toStrictEqual('-41763576480'); }); }); describe('Subtraction', () => { - it('Should compute correct results for simple subtraction', () => { - expect(new Numeric(25, 10).minus(5, 10).toNumber()).toEqual(20); + it('should compute correct results for simple subtraction', () => { + expect(new Numeric(25, 10).minus(5, 10).toNumber()).toStrictEqual(20); expect( new Numeric(50, 10).minus(new Numeric(10, 10)).toNumber(), - ).toEqual(40); + ).toStrictEqual(40); expect( new Numeric(250, 10).minus(new Numeric(100, 10)).toNumber(), - ).toEqual(150); + ).toStrictEqual(150); }); - it('Should compute correct results for subtraction of big numbers', () => { + it('should compute correct results for subtraction of big numbers', () => { expect( new Numeric('175671432', 10).minus('686216', 10).toString(), - ).toEqual('174985216'); + ).toStrictEqual('174985216'); expect( new Numeric('1756714320', 10) .minus(new Numeric('686216', 10)) .toString(), - ).toEqual('1756028104'); + ).toStrictEqual('1756028104'); expect( new Numeric('41756714320', 10) .minus(new Numeric('6862160', 10)) .toString(), - ).toEqual('41749852160'); + ).toStrictEqual('41749852160'); }); - it('Should compute correct results for subtraction of negative big numbers', () => { + it('should compute correct results for subtraction of negative big numbers', () => { expect( new Numeric('175671432', 10).minus('-686216', 10).toString(), - ).toEqual('176357648'); + ).toStrictEqual('176357648'); expect( new Numeric('1756714320', 10) .minus(new Numeric('-686216', 10)) .toString(), - ).toEqual('1757400536'); + ).toStrictEqual('1757400536'); expect( new Numeric('-41756714320', 10) .minus(new Numeric('-6862160', 10)) .toString(), - ).toEqual('-41749852160'); + ).toStrictEqual('-41749852160'); }); }); describe('applyConversionRate', () => { - it('Should multiply the value by the conversionRate supplied', () => { + it('should multiply the value by the conversionRate supplied', () => { expect( new Numeric(10, 10).applyConversionRate(468.5).toString(), - ).toEqual('4685'); + ).toStrictEqual('4685'); }); - it('Should multiply the value by the conversionRate supplied when conversionRate is a BigNumber', () => { + it('should multiply the value by the conversionRate supplied when conversionRate is a BigNumber', () => { expect( new Numeric(10, 10) .applyConversionRate(new BigNumber(468.5, 10)) .toString(), - ).toEqual('4685'); + ).toStrictEqual('4685'); }); - it('Should multiply the value by the inverse of conversionRate supplied when second parameter is true', () => { + it('should multiply the value by the inverse of conversionRate supplied when second parameter is true', () => { expect( new Numeric(10, 10).applyConversionRate(468.5, true).toString(), - ).toEqual('0.0213447171824973319'); + ).toStrictEqual('0.0213447171824973319'); }); - it('Should multiply the value by the inverse of the BigNumber conversionRate supplied when second parameter is true', () => { + it('should multiply the value by the inverse of the BigNumber conversionRate supplied when second parameter is true', () => { expect( new Numeric(10, 10) .applyConversionRate(new BigNumber(468.5, 10), true) .toString(), - ).toEqual('0.0213447171824973319'); + ).toStrictEqual('0.0213447171824973319'); }); }); }); describe('Base conversion', () => { it('should convert a hexadecimal string to a decimal string', () => { - expect(new Numeric('0x5208', 16).toBase(10).toString()).toEqual('21000'); + expect(new Numeric('0x5208', 16).toBase(10).toString()).toStrictEqual( + '21000', + ); }); it('should convert a decimal string to a hexadecimal string', () => { - expect(new Numeric('21000', 10).toBase(16).toString()).toEqual('5208'); + expect(new Numeric('21000', 10).toBase(16).toString()).toStrictEqual( + '5208', + ); }); it('should convert a decimal string to a 0x prefixed hexadecimal string', () => { - expect(new Numeric('21000', 10).toPrefixedHexString()).toEqual('0x5208'); + expect(new Numeric('21000', 10).toPrefixedHexString()).toStrictEqual( + '0x5208', + ); }); it('should convert a decimal number to a hexadecimal string', () => { - expect(new Numeric(21000, 10).toBase(16).toString()).toEqual('5208'); + expect(new Numeric(21000, 10).toBase(16).toString()).toStrictEqual( + '5208', + ); }); it('should convert a decimal number to a 0x prefixed hexadecimal string', () => { - expect(new Numeric(21000, 10).toPrefixedHexString()).toEqual('0x5208'); + expect(new Numeric(21000, 10).toPrefixedHexString()).toStrictEqual( + '0x5208', + ); }); }); describe('Comparisons', () => { - it('Should correctly identify that 0xa is greater than 0x9', () => { - expect(new Numeric('0xa', 16).greaterThan('0x9', 16)).toEqual(true); + it('should correctly identify that 0xa is greater than 0x9', () => { + expect(new Numeric('0xa', 16).greaterThan('0x9', 16)).toStrictEqual(true); }); - it('Should correctly identify that 0x9 is less than 0xa', () => { - expect(new Numeric('0x9', 16).lessThan('0xa', 16)).toEqual(true); + it('should correctly identify that 0x9 is less than 0xa', () => { + expect(new Numeric('0x9', 16).lessThan('0xa', 16)).toStrictEqual(true); }); - it('Should correctly identify that 0xa is greater than or equal to 0xa', () => { - expect(new Numeric('0xa', 16).greaterThanOrEqualTo('0xa', 16)).toEqual( + it('should correctly identify that 0xa is greater than or equal to 0xa', () => { + expect( + new Numeric('0xa', 16).greaterThanOrEqualTo('0xa', 16), + ).toStrictEqual(true); + }); + it('should correctly identify that 0xa is less than or equal to 0xa', () => { + expect(new Numeric('0xa', 16).lessThanOrEqualTo('0xa', 16)).toStrictEqual( true, ); }); - it('Should correctly identify that 0xa is less than or equal to 0xa', () => { - expect(new Numeric('0xa', 16).lessThanOrEqualTo('0xa', 16)).toEqual(true); - }); - it('Should correctly identify that 0xa is greater than 9', () => { - expect(new Numeric('0xa', 16).greaterThan(9, 10)).toEqual(true); + it('should correctly identify that 0xa is greater than 9', () => { + expect(new Numeric('0xa', 16).greaterThan(9, 10)).toStrictEqual(true); }); - it('Should correctly identify that 0x9 is less than 10', () => { - expect(new Numeric('0x9', 16).lessThan(10, 10)).toEqual(true); + it('should correctly identify that 0x9 is less than 10', () => { + expect(new Numeric('0x9', 16).lessThan(10, 10)).toStrictEqual(true); }); - it('Should correctly identify that 10 is greater than or equal to 0xa', () => { - expect(new Numeric(10, 10).greaterThanOrEqualTo('0xa', 16)).toEqual(true); + it('should correctly identify that 10 is greater than or equal to 0xa', () => { + expect(new Numeric(10, 10).greaterThanOrEqualTo('0xa', 16)).toStrictEqual( + true, + ); }); - it('Should correctly identify that 10 is less than or equal to 0xa', () => { - expect(new Numeric(10, 10).lessThanOrEqualTo('0xa', 16)).toEqual(true); + it('should correctly identify that 10 is less than or equal to 0xa', () => { + expect(new Numeric(10, 10).lessThanOrEqualTo('0xa', 16)).toStrictEqual( + true, + ); }); }); describe('Positive and Negative determination', () => { - it('Should correctly identify a negative number with isNegative', () => { - expect(new Numeric(-10, 10).isNegative()).toEqual(true); - expect(new Numeric('-10', 10).isNegative()).toEqual(true); - expect(new Numeric('-0xa', 16).isNegative()).toEqual(true); + it('should correctly identify a negative number with isNegative', () => { + expect(new Numeric(-10, 10).isNegative()).toStrictEqual(true); + expect(new Numeric('-10', 10).isNegative()).toStrictEqual(true); + expect(new Numeric('-0xa', 16).isNegative()).toStrictEqual(true); }); - it('Should return false for isNegative when number is positive', () => { - expect(new Numeric(10, 10).isNegative()).toEqual(false); - expect(new Numeric('10', 10).isNegative()).toEqual(false); - expect(new Numeric('0xa', 16).isNegative()).toEqual(false); + it('should return false for isNegative when number is positive', () => { + expect(new Numeric(10, 10).isNegative()).toStrictEqual(false); + expect(new Numeric('10', 10).isNegative()).toStrictEqual(false); + expect(new Numeric('0xa', 16).isNegative()).toStrictEqual(false); }); - it('Should correctly identify a positive number with isPositive', () => { - expect(new Numeric(10, 10).isPositive()).toEqual(true); - expect(new Numeric('10', 10).isPositive()).toEqual(true); - expect(new Numeric('0xa', 16).isPositive()).toEqual(true); + it('should correctly identify a positive number with isPositive', () => { + expect(new Numeric(10, 10).isPositive()).toStrictEqual(true); + expect(new Numeric('10', 10).isPositive()).toStrictEqual(true); + expect(new Numeric('0xa', 16).isPositive()).toStrictEqual(true); }); - it('Should return false for isPositive when number is negative', () => { - expect(new Numeric(-10, 10).isPositive()).toEqual(false); - expect(new Numeric('-10', 10).isPositive()).toEqual(false); - expect(new Numeric('-0xa', 16).isPositive()).toEqual(false); + it('should return false for isPositive when number is negative', () => { + expect(new Numeric(-10, 10).isPositive()).toStrictEqual(false); + expect(new Numeric('-10', 10).isPositive()).toStrictEqual(false); + expect(new Numeric('-0xa', 16).isPositive()).toStrictEqual(false); }); }); describe('Terminating functions, return values', () => { describe('toString', () => { - it('Should return a string representation of provided hex', () => { - expect(new Numeric('0xa', 16).toString()).toEqual('a'); + it('should return a string representation of provided hex', () => { + expect(new Numeric('0xa', 16).toString()).toStrictEqual('a'); }); - it('Should return a string representation of provided decimal string', () => { - expect(new Numeric('10', 10).toString()).toEqual('10'); + it('should return a string representation of provided decimal string', () => { + expect(new Numeric('10', 10).toString()).toStrictEqual('10'); }); - it('Should return a string representation of provided number', () => { - expect(new Numeric(10, 10).toString()).toEqual('10'); + it('should return a string representation of provided number', () => { + expect(new Numeric(10, 10).toString()).toStrictEqual('10'); }); - it('Should return a string representation of provided float', () => { - expect(new Numeric(10.5, 10).toString()).toEqual('10.5'); + it('should return a string representation of provided float', () => { + expect(new Numeric(10.5, 10).toString()).toStrictEqual('10.5'); }); - it('Should return a string representation of provided BigNumber', () => { - expect(new Numeric(new BigNumber(10, 10)).toString()).toEqual('10'); + it('should return a string representation of provided BigNumber', () => { + expect(new Numeric(new BigNumber(10, 10)).toString()).toStrictEqual( + '10', + ); }); - it('Should return a string representation of provided BN', () => { - expect(new Numeric(new BN(10, 10)).toString()).toEqual('10'); + it('should return a string representation of provided BN', () => { + expect(new Numeric(new BN(10, 10)).toString()).toStrictEqual('10'); }); }); describe('toNumber', () => { - it('Should return a number representing provided hex', () => { - expect(new Numeric('0xa', 16).toNumber()).toEqual(10); + it('should return a number representing provided hex', () => { + expect(new Numeric('0xa', 16).toNumber()).toStrictEqual(10); }); - it('Should return a number representation of provided decimal string', () => { - expect(new Numeric('10', 10).toNumber()).toEqual(10); + it('should return a number representation of provided decimal string', () => { + expect(new Numeric('10', 10).toNumber()).toStrictEqual(10); }); - it('Should return a number representation of provided number', () => { - expect(new Numeric(10, 10).toNumber()).toEqual(10); + it('should return a number representation of provided number', () => { + expect(new Numeric(10, 10).toNumber()).toStrictEqual(10); }); - it('Should return a number representation of provided float', () => { - expect(new Numeric(10.5, 10).toNumber()).toEqual(10.5); + it('should return a number representation of provided float', () => { + expect(new Numeric(10.5, 10).toNumber()).toStrictEqual(10.5); }); - it('Should return a number representation of provided BigNumber', () => { - expect(new Numeric(new BigNumber(10, 10)).toNumber()).toEqual(10); + it('should return a number representation of provided BigNumber', () => { + expect(new Numeric(new BigNumber(10, 10)).toNumber()).toStrictEqual(10); }); - it('Should return a number representation of provided BN', () => { - expect(new Numeric(new BN(10, 10)).toNumber()).toEqual(10); + it('should return a number representation of provided BN', () => { + expect(new Numeric(new BN(10, 10)).toNumber()).toStrictEqual(10); }); }); describe('toFixed', () => { - it('Should return a string representing provided hex to 2 decimal places', () => { - expect(new Numeric('0xa.7', 16).toFixed(2)).toEqual('10.44'); + it('should return a string representing provided hex to 2 decimal places', () => { + expect(new Numeric('0xa.7', 16).toFixed(2)).toStrictEqual('10.44'); }); - it('Should return a string representation of provided decimal string to 2 decimal places', () => { - expect(new Numeric('10.4375', 10).toFixed(2)).toEqual('10.44'); + it('should return a string representation of provided decimal string to 2 decimal places', () => { + expect(new Numeric('10.4375', 10).toFixed(2)).toStrictEqual('10.44'); }); - it('Should return a string representation of provided float to 2 decimal places', () => { - expect(new Numeric(10.4375, 10).toFixed(2)).toEqual('10.44'); + it('should return a string representation of provided float to 2 decimal places', () => { + expect(new Numeric(10.4375, 10).toFixed(2)).toStrictEqual('10.44'); }); - it('Should return a number representation of provided BigNumber to 2 decimal places', () => { - expect(new Numeric(new BigNumber(10.4375, 10)).toFixed(2)).toEqual( - '10.44', - ); + it('should return a number representation of provided BigNumber to 2 decimal places', () => { + expect( + new Numeric(new BigNumber(10.4375, 10)).toFixed(2), + ).toStrictEqual('10.44'); }); }); describe('round', () => { it('should return number rounded', () => { - expect(new Numeric(10.4375, 10).round()).toEqual( + expect(new Numeric(10.4375, 10).round()).toStrictEqual( new Numeric(10.4375, 10), ); - expect(new Numeric(10.4375, 10).round(0)).toEqual(new Numeric(10, 10)); - expect(new Numeric(10.4375, 10).round(1)).toEqual( + expect(new Numeric(10.4375, 10).round(0)).toStrictEqual( + new Numeric(10, 10), + ); + expect(new Numeric(10.4375, 10).round(1)).toStrictEqual( new Numeric(10.4, 10), ); - expect(new Numeric(10.4375, 10).round(2)).toEqual( + expect(new Numeric(10.4375, 10).round(2)).toStrictEqual( new Numeric(10.44, 10), ); - expect(new Numeric(10.4375, 10).round(3)).toEqual( + expect(new Numeric(10.4375, 10).round(3)).toStrictEqual( new Numeric(10.437, 10), ); - expect(new Numeric(10.4375, 10).round(4)).toEqual( + expect(new Numeric(10.4375, 10).round(4)).toStrictEqual( new Numeric(10.4375, 10), ); - expect(new Numeric(10.4375, 10).round(5)).toEqual( + expect(new Numeric(10.4375, 10).round(5)).toStrictEqual( new Numeric(10.4375, 10), ); }); diff --git a/shared/modules/error.test.ts b/shared/modules/error.test.ts index 5f1d3eee6..247ef302d 100644 --- a/shared/modules/error.test.ts +++ b/shared/modules/error.test.ts @@ -3,11 +3,11 @@ import { isErrorWithMessage, logErrorWithMessage } from './error'; jest.mock('loglevel'); -afterEach(() => { - jest.resetAllMocks(); -}); - describe('error module', () => { + afterEach(() => { + jest.resetAllMocks(); + }); + describe('isErrorWithMessage', () => { it('returns true when passed an instance of an Error', () => { expect(isErrorWithMessage(new Error('test'))).toBe(true); @@ -21,12 +21,12 @@ describe('error module', () => { describe('logErrorWithMessage', () => { it('calls loglevel.error with the error.message when passed an instance of Error', () => { logErrorWithMessage(new Error('test')); - expect(log.error).toBeCalledWith('test'); + expect(log.error).toHaveBeenCalledWith('test'); }); it('calls loglevel.error with the parameter passed in when parameter is not an instance of Error', () => { logErrorWithMessage({ test: 'test' }); - expect(log.error).toBeCalledWith({ test: 'test' }); + expect(log.error).toHaveBeenCalledWith({ test: 'test' }); }); }); });