mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
Ensure that TS files in shared/modules are linted (#18367)
Some TypeScript files in shared/modules are not being linted. Add them to the ESLint config and fix any lint violations that arise from doing so.
This commit is contained in:
parent
9b0a6ecc90
commit
50d8740a0d
@ -81,6 +81,7 @@ module.exports = {
|
|||||||
files: [
|
files: [
|
||||||
'app/**/*.js',
|
'app/**/*.js',
|
||||||
'shared/**/*.js',
|
'shared/**/*.js',
|
||||||
|
'shared/**/*.ts',
|
||||||
'ui/**/*.js',
|
'ui/**/*.js',
|
||||||
'**/*.test.js',
|
'**/*.test.js',
|
||||||
'test/lib/**/*.js',
|
'test/lib/**/*.js',
|
||||||
@ -272,6 +273,7 @@ module.exports = {
|
|||||||
'app/scripts/platforms/*.test.js',
|
'app/scripts/platforms/*.test.js',
|
||||||
'development/**/*.test.js',
|
'development/**/*.test.js',
|
||||||
'shared/**/*.test.js',
|
'shared/**/*.test.js',
|
||||||
|
'shared/**/*.test.ts',
|
||||||
'test/helpers/*.js',
|
'test/helpers/*.js',
|
||||||
'test/jest/*.js',
|
'test/jest/*.js',
|
||||||
'ui/**/*.test.js',
|
'ui/**/*.test.js',
|
||||||
|
@ -10,98 +10,98 @@ const ONE_WEI = new Numeric(1, 10, EtherDenomination.WEI);
|
|||||||
describe('Numeric', () => {
|
describe('Numeric', () => {
|
||||||
describe('Basic Numeric Construction', () => {
|
describe('Basic Numeric Construction', () => {
|
||||||
describe('From hexadeciaml strings', () => {
|
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);
|
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);
|
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);
|
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);
|
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', () => {
|
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);
|
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);
|
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);
|
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);
|
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', () => {
|
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);
|
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);
|
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);
|
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);
|
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', () => {
|
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));
|
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);
|
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', () => {
|
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(
|
expect(() => new Numeric('Hello there', 10)).toThrow(
|
||||||
'String provided to stringToBigNumber is not a hexadecimal or decimal string: Hello there, 10',
|
'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(
|
expect(() => new Numeric('10')).toThrow(
|
||||||
'You must specify the base of the provided number if the value is not already a BigNumber',
|
'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(
|
expect(() => new Numeric(true as unknown as number, 10)).toThrow(
|
||||||
'Value: true is not a string, number, BigNumber or BN. Type is: boolean.',
|
'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', () => {
|
describe('Erroneous behaviors that we are temporarily continuing', () => {
|
||||||
it('Handles values that are undefined, setting the value to 0', () => {
|
it('handles values that are undefined, setting the value to 0', () => {
|
||||||
expect(new Numeric(undefined as unknown as number).toString()).toEqual(
|
expect(
|
||||||
'0',
|
new Numeric(undefined as unknown as number).toString(),
|
||||||
);
|
).toStrictEqual('0');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Handles values that are NaN, setting the value to 0', () => {
|
it('handles values that are NaN, setting the value to 0', () => {
|
||||||
expect(new Numeric(NaN).toString()).toEqual('0');
|
expect(new Numeric(NaN).toString()).toStrictEqual('0');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Ether denomination conversion', () => {
|
describe('Ether denomination conversion', () => {
|
||||||
it('should convert 1 ETH to 1000000000 GWEI', () => {
|
it('should convert 1 ETH to 1000000000 GWEI', () => {
|
||||||
expect(ONE_ETH.toDenomination(EtherDenomination.GWEI).toString()).toEqual(
|
expect(
|
||||||
'1000000000',
|
ONE_ETH.toDenomination(EtherDenomination.GWEI).toString(),
|
||||||
);
|
).toStrictEqual('1000000000');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should convert 1 ETH to 1000000000000000000 WEI', () => {
|
it('should convert 1 ETH to 1000000000000000000 WEI', () => {
|
||||||
expect(ONE_ETH.toDenomination(EtherDenomination.WEI).toString()).toEqual(
|
expect(
|
||||||
'1000000000000000000',
|
ONE_ETH.toDenomination(EtherDenomination.WEI).toString(),
|
||||||
);
|
).toStrictEqual('1000000000000000000');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should convert 1 GWEI to 0.000000001 ETH', () => {
|
it('should convert 1 GWEI to 0.000000001 ETH', () => {
|
||||||
expect(ONE_GWEI.toDenomination(EtherDenomination.ETH).toString()).toEqual(
|
expect(
|
||||||
'0.000000001',
|
ONE_GWEI.toDenomination(EtherDenomination.ETH).toString(),
|
||||||
);
|
).toStrictEqual('0.000000001');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should convert 1 GWEI to 1000000000 WEI', () => {
|
it('should convert 1 GWEI to 1000000000 WEI', () => {
|
||||||
expect(ONE_GWEI.toDenomination(EtherDenomination.WEI).toString()).toEqual(
|
expect(
|
||||||
'1000000000',
|
ONE_GWEI.toDenomination(EtherDenomination.WEI).toString(),
|
||||||
);
|
).toStrictEqual('1000000000');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should convert 1 WEI to 0 ETH due to rounding', () => {
|
it('should convert 1 WEI to 0 ETH due to rounding', () => {
|
||||||
expect(ONE_WEI.toDenomination(EtherDenomination.ETH).toString()).toEqual(
|
expect(
|
||||||
'0',
|
ONE_WEI.toDenomination(EtherDenomination.ETH).toString(),
|
||||||
);
|
).toStrictEqual('0');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should convert 1 WEI to 0.000000001 GWEI', () => {
|
it('should convert 1 WEI to 0.000000001 GWEI', () => {
|
||||||
expect(ONE_WEI.toDenomination(EtherDenomination.GWEI).toString()).toEqual(
|
expect(
|
||||||
'0.000000001',
|
ONE_WEI.toDenomination(EtherDenomination.GWEI).toString(),
|
||||||
);
|
).toStrictEqual('0.000000001');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Math operations', () => {
|
describe('Math operations', () => {
|
||||||
describe('Multiplication', () => {
|
describe('Multiplication', () => {
|
||||||
it('Should compute correct results for simple multiplication', () => {
|
it('should compute correct results for simple multiplication', () => {
|
||||||
expect(new Numeric(5, 10).times(5, 10).toNumber()).toEqual(25);
|
expect(new Numeric(5, 10).times(5, 10).toNumber()).toStrictEqual(25);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric(5, 10).times(new Numeric(10, 10)).toNumber(),
|
new Numeric(5, 10).times(new Numeric(10, 10)).toNumber(),
|
||||||
).toEqual(50);
|
).toStrictEqual(50);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric(25, 10).times(new Numeric(10, 10)).toNumber(),
|
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(
|
expect(
|
||||||
new Numeric('175671432', 10).times('686216', 10).toString(),
|
new Numeric('175671432', 10).times('686216', 10).toString(),
|
||||||
).toEqual('120548547381312');
|
).toStrictEqual('120548547381312');
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric('1756714320', 10)
|
new Numeric('1756714320', 10)
|
||||||
.times(new Numeric('686216', 10))
|
.times(new Numeric('686216', 10))
|
||||||
.toString(),
|
.toString(),
|
||||||
).toEqual('1205485473813120');
|
).toStrictEqual('1205485473813120');
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric('41756714320', 10)
|
new Numeric('41756714320', 10)
|
||||||
.times(new Numeric('6862160', 10))
|
.times(new Numeric('6862160', 10))
|
||||||
.toString(),
|
.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(
|
expect(
|
||||||
new Numeric('175671432', 10).times('-686216', 10).toString(),
|
new Numeric('175671432', 10).times('-686216', 10).toString(),
|
||||||
).toEqual('-120548547381312');
|
).toStrictEqual('-120548547381312');
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric('1756714320', 10)
|
new Numeric('1756714320', 10)
|
||||||
.times(new Numeric('-686216', 10))
|
.times(new Numeric('-686216', 10))
|
||||||
.toString(),
|
.toString(),
|
||||||
).toEqual('-1205485473813120');
|
).toStrictEqual('-1205485473813120');
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric('-41756714320', 10)
|
new Numeric('-41756714320', 10)
|
||||||
.times(new Numeric('-6862160', 10))
|
.times(new Numeric('-6862160', 10))
|
||||||
.toString(),
|
.toString(),
|
||||||
).toEqual('286541254738131200');
|
).toStrictEqual('286541254738131200');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Division', () => {
|
describe('Division', () => {
|
||||||
it('Should compute correct results for simple division', () => {
|
it('should compute correct results for simple division', () => {
|
||||||
expect(new Numeric(25, 10).divide(5, 10).toNumber()).toEqual(5);
|
expect(new Numeric(25, 10).divide(5, 10).toNumber()).toStrictEqual(5);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric(50, 10).divide(new Numeric(10, 10)).toNumber(),
|
new Numeric(50, 10).divide(new Numeric(10, 10)).toNumber(),
|
||||||
).toEqual(5);
|
).toStrictEqual(5);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric(250, 10).divide(new Numeric(10, 10)).toNumber(),
|
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(
|
expect(
|
||||||
new Numeric('175671432', 10).divide('686216', 10).toString(),
|
new Numeric('175671432', 10).divide('686216', 10).toString(),
|
||||||
).toEqual('256.00019818832554181191');
|
).toStrictEqual('256.00019818832554181191');
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric('1756714320', 10)
|
new Numeric('1756714320', 10)
|
||||||
.divide(new Numeric('686216', 10))
|
.divide(new Numeric('686216', 10))
|
||||||
.toString(),
|
.toString(),
|
||||||
).toEqual('2560.00198188325541811908');
|
).toStrictEqual('2560.00198188325541811908');
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric('41756714320', 10)
|
new Numeric('41756714320', 10)
|
||||||
.divide(new Numeric('6862160', 10))
|
.divide(new Numeric('6862160', 10))
|
||||||
.toString(),
|
.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(
|
expect(
|
||||||
new Numeric('175671432', 10).divide('-686216', 10).toString(),
|
new Numeric('175671432', 10).divide('-686216', 10).toString(),
|
||||||
).toEqual('-256.00019818832554181191');
|
).toStrictEqual('-256.00019818832554181191');
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric('1756714320', 10)
|
new Numeric('1756714320', 10)
|
||||||
.divide(new Numeric('-686216', 10))
|
.divide(new Numeric('-686216', 10))
|
||||||
.toString(),
|
.toString(),
|
||||||
).toEqual('-2560.00198188325541811908');
|
).toStrictEqual('-2560.00198188325541811908');
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric('-41756714320', 10)
|
new Numeric('-41756714320', 10)
|
||||||
.divide(new Numeric('-6862160', 10))
|
.divide(new Numeric('-6862160', 10))
|
||||||
.toString(),
|
.toString(),
|
||||||
).toEqual('6085.06859647691106007438');
|
).toStrictEqual('6085.06859647691106007438');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Addition', () => {
|
describe('Addition', () => {
|
||||||
it('Should compute correct results for simple addition', () => {
|
it('should compute correct results for simple addition', () => {
|
||||||
expect(new Numeric(25, 10).add(5, 10).toNumber()).toEqual(30);
|
expect(new Numeric(25, 10).add(5, 10).toNumber()).toStrictEqual(30);
|
||||||
|
|
||||||
expect(new Numeric(50, 10).add(new Numeric(10, 10)).toNumber()).toEqual(
|
expect(
|
||||||
60,
|
new Numeric(50, 10).add(new Numeric(10, 10)).toNumber(),
|
||||||
);
|
).toStrictEqual(60);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric(250, 10).add(new Numeric(100, 10)).toNumber(),
|
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(
|
expect(
|
||||||
new Numeric('175671432', 10).add('686216', 10).toString(),
|
new Numeric('175671432', 10).add('686216', 10).toString(),
|
||||||
).toEqual('176357648');
|
).toStrictEqual('176357648');
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric('1756714320', 10)
|
new Numeric('1756714320', 10)
|
||||||
.add(new Numeric('686216', 10))
|
.add(new Numeric('686216', 10))
|
||||||
.toString(),
|
.toString(),
|
||||||
).toEqual('1757400536');
|
).toStrictEqual('1757400536');
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric('41756714320', 10)
|
new Numeric('41756714320', 10)
|
||||||
.add(new Numeric('6862160', 10))
|
.add(new Numeric('6862160', 10))
|
||||||
.toString(),
|
.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(
|
expect(
|
||||||
new Numeric('175671432', 10).add('-686216', 10).toString(),
|
new Numeric('175671432', 10).add('-686216', 10).toString(),
|
||||||
).toEqual('174985216');
|
).toStrictEqual('174985216');
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric('1756714320', 10)
|
new Numeric('1756714320', 10)
|
||||||
.add(new Numeric('-686216', 10))
|
.add(new Numeric('-686216', 10))
|
||||||
.toString(),
|
.toString(),
|
||||||
).toEqual('1756028104');
|
).toStrictEqual('1756028104');
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric('-41756714320', 10)
|
new Numeric('-41756714320', 10)
|
||||||
.add(new Numeric('-6862160', 10))
|
.add(new Numeric('-6862160', 10))
|
||||||
.toString(),
|
.toString(),
|
||||||
).toEqual('-41763576480');
|
).toStrictEqual('-41763576480');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Subtraction', () => {
|
describe('Subtraction', () => {
|
||||||
it('Should compute correct results for simple subtraction', () => {
|
it('should compute correct results for simple subtraction', () => {
|
||||||
expect(new Numeric(25, 10).minus(5, 10).toNumber()).toEqual(20);
|
expect(new Numeric(25, 10).minus(5, 10).toNumber()).toStrictEqual(20);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric(50, 10).minus(new Numeric(10, 10)).toNumber(),
|
new Numeric(50, 10).minus(new Numeric(10, 10)).toNumber(),
|
||||||
).toEqual(40);
|
).toStrictEqual(40);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric(250, 10).minus(new Numeric(100, 10)).toNumber(),
|
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(
|
expect(
|
||||||
new Numeric('175671432', 10).minus('686216', 10).toString(),
|
new Numeric('175671432', 10).minus('686216', 10).toString(),
|
||||||
).toEqual('174985216');
|
).toStrictEqual('174985216');
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric('1756714320', 10)
|
new Numeric('1756714320', 10)
|
||||||
.minus(new Numeric('686216', 10))
|
.minus(new Numeric('686216', 10))
|
||||||
.toString(),
|
.toString(),
|
||||||
).toEqual('1756028104');
|
).toStrictEqual('1756028104');
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric('41756714320', 10)
|
new Numeric('41756714320', 10)
|
||||||
.minus(new Numeric('6862160', 10))
|
.minus(new Numeric('6862160', 10))
|
||||||
.toString(),
|
.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(
|
expect(
|
||||||
new Numeric('175671432', 10).minus('-686216', 10).toString(),
|
new Numeric('175671432', 10).minus('-686216', 10).toString(),
|
||||||
).toEqual('176357648');
|
).toStrictEqual('176357648');
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric('1756714320', 10)
|
new Numeric('1756714320', 10)
|
||||||
.minus(new Numeric('-686216', 10))
|
.minus(new Numeric('-686216', 10))
|
||||||
.toString(),
|
.toString(),
|
||||||
).toEqual('1757400536');
|
).toStrictEqual('1757400536');
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
new Numeric('-41756714320', 10)
|
new Numeric('-41756714320', 10)
|
||||||
.minus(new Numeric('-6862160', 10))
|
.minus(new Numeric('-6862160', 10))
|
||||||
.toString(),
|
.toString(),
|
||||||
).toEqual('-41749852160');
|
).toStrictEqual('-41749852160');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('applyConversionRate', () => {
|
describe('applyConversionRate', () => {
|
||||||
it('Should multiply the value by the conversionRate supplied', () => {
|
it('should multiply the value by the conversionRate supplied', () => {
|
||||||
expect(
|
expect(
|
||||||
new Numeric(10, 10).applyConversionRate(468.5).toString(),
|
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(
|
expect(
|
||||||
new Numeric(10, 10)
|
new Numeric(10, 10)
|
||||||
.applyConversionRate(new BigNumber(468.5, 10))
|
.applyConversionRate(new BigNumber(468.5, 10))
|
||||||
.toString(),
|
.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(
|
expect(
|
||||||
new Numeric(10, 10).applyConversionRate(468.5, true).toString(),
|
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(
|
expect(
|
||||||
new Numeric(10, 10)
|
new Numeric(10, 10)
|
||||||
.applyConversionRate(new BigNumber(468.5, 10), true)
|
.applyConversionRate(new BigNumber(468.5, 10), true)
|
||||||
.toString(),
|
.toString(),
|
||||||
).toEqual('0.0213447171824973319');
|
).toStrictEqual('0.0213447171824973319');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Base conversion', () => {
|
describe('Base conversion', () => {
|
||||||
it('should convert a hexadecimal string to a decimal string', () => {
|
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', () => {
|
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', () => {
|
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', () => {
|
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', () => {
|
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', () => {
|
describe('Comparisons', () => {
|
||||||
it('Should correctly identify that 0xa is greater than 0x9', () => {
|
it('should correctly identify that 0xa is greater than 0x9', () => {
|
||||||
expect(new Numeric('0xa', 16).greaterThan('0x9', 16)).toEqual(true);
|
expect(new Numeric('0xa', 16).greaterThan('0x9', 16)).toStrictEqual(true);
|
||||||
});
|
});
|
||||||
it('Should correctly identify that 0x9 is less than 0xa', () => {
|
it('should correctly identify that 0x9 is less than 0xa', () => {
|
||||||
expect(new Numeric('0x9', 16).lessThan('0xa', 16)).toEqual(true);
|
expect(new Numeric('0x9', 16).lessThan('0xa', 16)).toStrictEqual(true);
|
||||||
});
|
});
|
||||||
it('Should correctly identify that 0xa is greater than or equal to 0xa', () => {
|
it('should correctly identify that 0xa is greater than or equal to 0xa', () => {
|
||||||
expect(new Numeric('0xa', 16).greaterThanOrEqualTo('0xa', 16)).toEqual(
|
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,
|
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', () => {
|
it('should correctly identify that 0xa is greater than 9', () => {
|
||||||
expect(new Numeric('0xa', 16).greaterThan(9, 10)).toEqual(true);
|
expect(new Numeric('0xa', 16).greaterThan(9, 10)).toStrictEqual(true);
|
||||||
});
|
});
|
||||||
it('Should correctly identify that 0x9 is less than 10', () => {
|
it('should correctly identify that 0x9 is less than 10', () => {
|
||||||
expect(new Numeric('0x9', 16).lessThan(10, 10)).toEqual(true);
|
expect(new Numeric('0x9', 16).lessThan(10, 10)).toStrictEqual(true);
|
||||||
});
|
});
|
||||||
it('Should correctly identify that 10 is greater than or equal to 0xa', () => {
|
it('should correctly identify that 10 is greater than or equal to 0xa', () => {
|
||||||
expect(new Numeric(10, 10).greaterThanOrEqualTo('0xa', 16)).toEqual(true);
|
expect(new Numeric(10, 10).greaterThanOrEqualTo('0xa', 16)).toStrictEqual(
|
||||||
|
true,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
it('Should correctly identify that 10 is less than or equal to 0xa', () => {
|
it('should correctly identify that 10 is less than or equal to 0xa', () => {
|
||||||
expect(new Numeric(10, 10).lessThanOrEqualTo('0xa', 16)).toEqual(true);
|
expect(new Numeric(10, 10).lessThanOrEqualTo('0xa', 16)).toStrictEqual(
|
||||||
|
true,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Positive and Negative determination', () => {
|
describe('Positive and Negative determination', () => {
|
||||||
it('Should correctly identify a negative number with isNegative', () => {
|
it('should correctly identify a negative number with isNegative', () => {
|
||||||
expect(new Numeric(-10, 10).isNegative()).toEqual(true);
|
expect(new Numeric(-10, 10).isNegative()).toStrictEqual(true);
|
||||||
expect(new Numeric('-10', 10).isNegative()).toEqual(true);
|
expect(new Numeric('-10', 10).isNegative()).toStrictEqual(true);
|
||||||
expect(new Numeric('-0xa', 16).isNegative()).toEqual(true);
|
expect(new Numeric('-0xa', 16).isNegative()).toStrictEqual(true);
|
||||||
});
|
});
|
||||||
it('Should return false for isNegative when number is positive', () => {
|
it('should return false for isNegative when number is positive', () => {
|
||||||
expect(new Numeric(10, 10).isNegative()).toEqual(false);
|
expect(new Numeric(10, 10).isNegative()).toStrictEqual(false);
|
||||||
expect(new Numeric('10', 10).isNegative()).toEqual(false);
|
expect(new Numeric('10', 10).isNegative()).toStrictEqual(false);
|
||||||
expect(new Numeric('0xa', 16).isNegative()).toEqual(false);
|
expect(new Numeric('0xa', 16).isNegative()).toStrictEqual(false);
|
||||||
});
|
});
|
||||||
it('Should correctly identify a positive number with isPositive', () => {
|
it('should correctly identify a positive number with isPositive', () => {
|
||||||
expect(new Numeric(10, 10).isPositive()).toEqual(true);
|
expect(new Numeric(10, 10).isPositive()).toStrictEqual(true);
|
||||||
expect(new Numeric('10', 10).isPositive()).toEqual(true);
|
expect(new Numeric('10', 10).isPositive()).toStrictEqual(true);
|
||||||
expect(new Numeric('0xa', 16).isPositive()).toEqual(true);
|
expect(new Numeric('0xa', 16).isPositive()).toStrictEqual(true);
|
||||||
});
|
});
|
||||||
it('Should return false for isPositive when number is negative', () => {
|
it('should return false for isPositive when number is negative', () => {
|
||||||
expect(new Numeric(-10, 10).isPositive()).toEqual(false);
|
expect(new Numeric(-10, 10).isPositive()).toStrictEqual(false);
|
||||||
expect(new Numeric('-10', 10).isPositive()).toEqual(false);
|
expect(new Numeric('-10', 10).isPositive()).toStrictEqual(false);
|
||||||
expect(new Numeric('-0xa', 16).isPositive()).toEqual(false);
|
expect(new Numeric('-0xa', 16).isPositive()).toStrictEqual(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Terminating functions, return values', () => {
|
describe('Terminating functions, return values', () => {
|
||||||
describe('toString', () => {
|
describe('toString', () => {
|
||||||
it('Should return a string representation of provided hex', () => {
|
it('should return a string representation of provided hex', () => {
|
||||||
expect(new Numeric('0xa', 16).toString()).toEqual('a');
|
expect(new Numeric('0xa', 16).toString()).toStrictEqual('a');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return a string representation of provided decimal string', () => {
|
it('should return a string representation of provided decimal string', () => {
|
||||||
expect(new Numeric('10', 10).toString()).toEqual('10');
|
expect(new Numeric('10', 10).toString()).toStrictEqual('10');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return a string representation of provided number', () => {
|
it('should return a string representation of provided number', () => {
|
||||||
expect(new Numeric(10, 10).toString()).toEqual('10');
|
expect(new Numeric(10, 10).toString()).toStrictEqual('10');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return a string representation of provided float', () => {
|
it('should return a string representation of provided float', () => {
|
||||||
expect(new Numeric(10.5, 10).toString()).toEqual('10.5');
|
expect(new Numeric(10.5, 10).toString()).toStrictEqual('10.5');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return a string representation of provided BigNumber', () => {
|
it('should return a string representation of provided BigNumber', () => {
|
||||||
expect(new Numeric(new BigNumber(10, 10)).toString()).toEqual('10');
|
expect(new Numeric(new BigNumber(10, 10)).toString()).toStrictEqual(
|
||||||
|
'10',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return a string representation of provided BN', () => {
|
it('should return a string representation of provided BN', () => {
|
||||||
expect(new Numeric(new BN(10, 10)).toString()).toEqual('10');
|
expect(new Numeric(new BN(10, 10)).toString()).toStrictEqual('10');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toNumber', () => {
|
describe('toNumber', () => {
|
||||||
it('Should return a number representing provided hex', () => {
|
it('should return a number representing provided hex', () => {
|
||||||
expect(new Numeric('0xa', 16).toNumber()).toEqual(10);
|
expect(new Numeric('0xa', 16).toNumber()).toStrictEqual(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return a number representation of provided decimal string', () => {
|
it('should return a number representation of provided decimal string', () => {
|
||||||
expect(new Numeric('10', 10).toNumber()).toEqual(10);
|
expect(new Numeric('10', 10).toNumber()).toStrictEqual(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return a number representation of provided number', () => {
|
it('should return a number representation of provided number', () => {
|
||||||
expect(new Numeric(10, 10).toNumber()).toEqual(10);
|
expect(new Numeric(10, 10).toNumber()).toStrictEqual(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return a number representation of provided float', () => {
|
it('should return a number representation of provided float', () => {
|
||||||
expect(new Numeric(10.5, 10).toNumber()).toEqual(10.5);
|
expect(new Numeric(10.5, 10).toNumber()).toStrictEqual(10.5);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return a number representation of provided BigNumber', () => {
|
it('should return a number representation of provided BigNumber', () => {
|
||||||
expect(new Numeric(new BigNumber(10, 10)).toNumber()).toEqual(10);
|
expect(new Numeric(new BigNumber(10, 10)).toNumber()).toStrictEqual(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return a number representation of provided BN', () => {
|
it('should return a number representation of provided BN', () => {
|
||||||
expect(new Numeric(new BN(10, 10)).toNumber()).toEqual(10);
|
expect(new Numeric(new BN(10, 10)).toNumber()).toStrictEqual(10);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toFixed', () => {
|
describe('toFixed', () => {
|
||||||
it('Should return a string representing provided hex to 2 decimal places', () => {
|
it('should return a string representing provided hex to 2 decimal places', () => {
|
||||||
expect(new Numeric('0xa.7', 16).toFixed(2)).toEqual('10.44');
|
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', () => {
|
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');
|
expect(new Numeric('10.4375', 10).toFixed(2)).toStrictEqual('10.44');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return a string representation of provided float to 2 decimal places', () => {
|
it('should return a string representation of provided float to 2 decimal places', () => {
|
||||||
expect(new Numeric(10.4375, 10).toFixed(2)).toEqual('10.44');
|
expect(new Numeric(10.4375, 10).toFixed(2)).toStrictEqual('10.44');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should return a number representation of provided BigNumber to 2 decimal places', () => {
|
it('should return a number representation of provided BigNumber to 2 decimal places', () => {
|
||||||
expect(new Numeric(new BigNumber(10.4375, 10)).toFixed(2)).toEqual(
|
expect(
|
||||||
'10.44',
|
new Numeric(new BigNumber(10.4375, 10)).toFixed(2),
|
||||||
);
|
).toStrictEqual('10.44');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('round', () => {
|
describe('round', () => {
|
||||||
it('should return number rounded', () => {
|
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),
|
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(0)).toStrictEqual(
|
||||||
expect(new Numeric(10.4375, 10).round(1)).toEqual(
|
new Numeric(10, 10),
|
||||||
|
);
|
||||||
|
expect(new Numeric(10.4375, 10).round(1)).toStrictEqual(
|
||||||
new Numeric(10.4, 10),
|
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),
|
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),
|
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),
|
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),
|
new Numeric(10.4375, 10),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -3,11 +3,11 @@ import { isErrorWithMessage, logErrorWithMessage } from './error';
|
|||||||
|
|
||||||
jest.mock('loglevel');
|
jest.mock('loglevel');
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
jest.resetAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('error module', () => {
|
describe('error module', () => {
|
||||||
|
afterEach(() => {
|
||||||
|
jest.resetAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
describe('isErrorWithMessage', () => {
|
describe('isErrorWithMessage', () => {
|
||||||
it('returns true when passed an instance of an Error', () => {
|
it('returns true when passed an instance of an Error', () => {
|
||||||
expect(isErrorWithMessage(new Error('test'))).toBe(true);
|
expect(isErrorWithMessage(new Error('test'))).toBe(true);
|
||||||
@ -21,12 +21,12 @@ describe('error module', () => {
|
|||||||
describe('logErrorWithMessage', () => {
|
describe('logErrorWithMessage', () => {
|
||||||
it('calls loglevel.error with the error.message when passed an instance of Error', () => {
|
it('calls loglevel.error with the error.message when passed an instance of Error', () => {
|
||||||
logErrorWithMessage(new Error('test'));
|
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', () => {
|
it('calls loglevel.error with the parameter passed in when parameter is not an instance of Error', () => {
|
||||||
logErrorWithMessage({ test: 'test' });
|
logErrorWithMessage({ test: 'test' });
|
||||||
expect(log.error).toBeCalledWith({ test: 'test' });
|
expect(log.error).toHaveBeenCalledWith({ test: 'test' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user