Update tests to use jest (#11)
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
// ISC, Copyright 2017 Jaco Greeff
|
||||
|
||||
/* eslint-disable no-unused-expressions */
|
||||
|
||||
const BN = require('bn.js');
|
||||
|
||||
const { bnFromHex, bnToHex } = require('./index');
|
||||
@@ -15,7 +13,7 @@ describe('bn', () => {
|
||||
bnFromHex(`0x${value}`).eq(
|
||||
new BN(value, 16)
|
||||
)
|
||||
).to.be.true;
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('converts null values to BN(0)', () => {
|
||||
@@ -23,13 +21,13 @@ describe('bn', () => {
|
||||
bnFromHex(null).eq(
|
||||
new BN(0)
|
||||
)
|
||||
).to.be.true;
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('throws when trying to convert non-BN values', () => {
|
||||
expect(
|
||||
() => bnFromHex('noAHex')
|
||||
).to.throw(/Cannot convert from non-hex/);
|
||||
).toThrow(/Cannot convert from non-hex/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -37,19 +35,19 @@ describe('bn', () => {
|
||||
it('converts BN values to a prefixed hex representation', () => {
|
||||
expect(
|
||||
bnToHex(new BN(128))
|
||||
).to.equal('0x80');
|
||||
).toEqual('0x80');
|
||||
});
|
||||
|
||||
it('converts null values to 0x', () => {
|
||||
expect(
|
||||
bnToHex(null)
|
||||
).to.equal('0x');
|
||||
).toEqual('0x');
|
||||
});
|
||||
|
||||
it('throws when trying to convert non-BN values', () => {
|
||||
expect(
|
||||
() => bnToHex('notABn')
|
||||
).to.throw(/Cannot convert from non-BN/);
|
||||
).toThrow(/Cannot convert from non-BN/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// ISC, Copyright 2017 Jaco Greeff
|
||||
|
||||
/* eslint-disable no-unused-expressions */
|
||||
|
||||
const { bufferFromHex, bufferToHex } = require('./');
|
||||
|
||||
describe('buffer', () => {
|
||||
@@ -9,7 +7,7 @@ describe('buffer', () => {
|
||||
it('returns an empty buffer when null provided', () => {
|
||||
expect(
|
||||
bufferFromHex(null).length
|
||||
).to.equal(0);
|
||||
).toEqual(0);
|
||||
});
|
||||
|
||||
it('returns a buffer with the correct values', () => {
|
||||
@@ -17,13 +15,13 @@ describe('buffer', () => {
|
||||
Buffer.from([128, 0, 10]).equals(
|
||||
bufferFromHex('0x80000a')
|
||||
)
|
||||
).to.be.true;
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('throws error on non-hex inputs', () => {
|
||||
expect(
|
||||
() => bufferFromHex('notAHex')
|
||||
).to.throw(/Cannot convert non-hex value/);
|
||||
).toThrow(/Cannot convert non-hex value/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -31,19 +29,19 @@ describe('buffer', () => {
|
||||
it('returns 0x when the buffer is null', () => {
|
||||
expect(
|
||||
bufferToHex(null)
|
||||
).to.equal('0x');
|
||||
).toEqual('0x');
|
||||
});
|
||||
|
||||
it('returns the hex value for the buffer', () => {
|
||||
expect(
|
||||
bufferToHex(Buffer.from([128, 0, 10]))
|
||||
).to.equal('0x80000a');
|
||||
).toEqual('0x80000a');
|
||||
});
|
||||
|
||||
it('throws when non-buffer value is supplied', () => {
|
||||
expect(
|
||||
() => bufferToHex('noABuffer')
|
||||
).to.throw(/Cannot convert non-buffer/);
|
||||
).toThrow(/Cannot convert non-buffer/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+10
-10
@@ -9,19 +9,19 @@ describe('hex', () => {
|
||||
it('does not add when prefix is available', () => {
|
||||
expect(
|
||||
hexAddPrefix('0x123')
|
||||
).to.equal('0x123');
|
||||
).toEqual('0x123');
|
||||
});
|
||||
|
||||
it('adds the prefix when it is not available', () => {
|
||||
expect(
|
||||
hexAddPrefix('123')
|
||||
).to.equal('0x123');
|
||||
).toEqual('0x123');
|
||||
});
|
||||
|
||||
it('returns null as 0x', () => {
|
||||
expect(
|
||||
hexAddPrefix(null)
|
||||
).to.equal('0x');
|
||||
).toEqual('0x');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,25 +29,25 @@ describe('hex', () => {
|
||||
it('returns true when hex prefix is found', () => {
|
||||
expect(
|
||||
hexHasPrefix('0x123')
|
||||
).to.be.true;
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('returns false when no prefix attached', () => {
|
||||
expect(
|
||||
hexHasPrefix('123')
|
||||
).to.be.false;
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
it('returns false when null value supplied', () => {
|
||||
expect(
|
||||
hexHasPrefix(null)
|
||||
).to.be.false;
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
it('returns false when non-string value supplied', () => {
|
||||
expect(
|
||||
hexHasPrefix(false)
|
||||
).to.be.false;
|
||||
).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -55,19 +55,19 @@ describe('hex', () => {
|
||||
it('returns the value as-is when no prefix', () => {
|
||||
expect(
|
||||
hexStripPrefix('01ab')
|
||||
).to.equal('01ab');
|
||||
).toEqual('01ab');
|
||||
});
|
||||
|
||||
it('returns an empty string when null value supplied', () => {
|
||||
expect(
|
||||
hexStripPrefix(null)
|
||||
).to.equal('');
|
||||
).toEqual('');
|
||||
});
|
||||
|
||||
it('strips the prefix from other strings', () => {
|
||||
expect(
|
||||
hexStripPrefix('0x1223')
|
||||
).to.equal('1223');
|
||||
).toEqual('1223');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+1
-3
@@ -1,11 +1,9 @@
|
||||
// ISC, Copyright 2017 Jaco Greeff
|
||||
|
||||
/* eslint-disable no-unused-expressions */
|
||||
|
||||
const util = require('./index');
|
||||
|
||||
describe('index', () => {
|
||||
it('exports ok', () => {
|
||||
expect(util).to.be.ok;
|
||||
expect(util).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
+20
-20
@@ -11,13 +11,13 @@ describe('is', () => {
|
||||
it('returns true when a BN value', () => {
|
||||
expect(
|
||||
isBN(new BN(123))
|
||||
).to.be.true;
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('returns false on non-BN values', () => {
|
||||
expect(
|
||||
isBN(0)
|
||||
).to.be.false;
|
||||
).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -25,13 +25,13 @@ describe('is', () => {
|
||||
it('returns true on valid functions', () => {
|
||||
expect(
|
||||
isFunction(isFunction)
|
||||
).to.be.true;
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('returns false on invalid functions', () => {
|
||||
expect(
|
||||
isFunction('notAFunction')
|
||||
).to.be.false;
|
||||
).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -41,25 +41,25 @@ describe('is', () => {
|
||||
it('returns true on hex values', () => {
|
||||
expect(
|
||||
isHex(`0x${test}`)
|
||||
).to.be.true;
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('returns true on uppercase values', () => {
|
||||
expect(
|
||||
isHex(`0x${test.toUpperCase()}`)
|
||||
).to.be.true;
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('return false on hex values unprefixed', () => {
|
||||
expect(
|
||||
isHex(test)
|
||||
).to.be.false;
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
it('returns false on non-string values', () => {
|
||||
expect(
|
||||
isHex(false)
|
||||
).to.be.false;
|
||||
).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -67,31 +67,31 @@ describe('is', () => {
|
||||
it('returns true on real instances', () => {
|
||||
expect(
|
||||
isInstanceOf(new Array(2), Array)
|
||||
).to.be.true;
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('returns false on non-allocated instances', () => {
|
||||
expect(
|
||||
isInstanceOf([], Array)
|
||||
).to.be.true;
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('returns false on non-instances', () => {
|
||||
expect(
|
||||
isInstanceOf('array', Array)
|
||||
).to.be.false;
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
it('returns false when class not specified', () => {
|
||||
expect(
|
||||
isInstanceOf('array', Array)
|
||||
).to.be.false;
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
it('returns false on wrong class type', () => {
|
||||
expect(
|
||||
isInstanceOf(new Array(2), String)
|
||||
).to.be.false;
|
||||
).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -99,13 +99,13 @@ describe('is', () => {
|
||||
it('returns true on valid numbers', () => {
|
||||
expect(
|
||||
isNumber(2)
|
||||
).to.be.true;
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('returns false on invalid numbers', () => {
|
||||
expect(
|
||||
isNumber('2')
|
||||
).to.be.false;
|
||||
).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -113,19 +113,19 @@ describe('is', () => {
|
||||
it('returns true on valid strings', () => {
|
||||
expect(
|
||||
isString('123')
|
||||
).to.be.true;
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('returns true on empty strings', () => {
|
||||
expect(
|
||||
isString('')
|
||||
).to.be.true;
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('returns false on invalid numbers', () => {
|
||||
expect(
|
||||
isString(2)
|
||||
).to.be.false;
|
||||
).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -133,13 +133,13 @@ describe('is', () => {
|
||||
it('returns true on undefined values', () => {
|
||||
expect(
|
||||
isUndefined()
|
||||
).to.be.true;
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('returns false on defined values', () => {
|
||||
expect(
|
||||
isUndefined(null)
|
||||
).to.be.false;
|
||||
).toEqual(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@ describe('jsonrpc', () => {
|
||||
],
|
||||
{ type: 'A' }
|
||||
)
|
||||
).to.equal('test_method (b: A, a: B): A');
|
||||
).toEqual('test_method (b: A, a: B): A');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@ describe('keccak', () => {
|
||||
keccakAsBuffer(value).equals(
|
||||
Buffer.from(result, 'hex')
|
||||
)
|
||||
).to.be.true;
|
||||
).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,7 +22,7 @@ describe('keccak', () => {
|
||||
it('returns a prefixed hex representation', () => {
|
||||
expect(
|
||||
keccakAsHex(value)
|
||||
).to.equal(`0x${result}`);
|
||||
).toEqual(`0x${result}`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -30,7 +30,7 @@ describe('keccak', () => {
|
||||
it('returns an un-prefixed hex representation', () => {
|
||||
expect(
|
||||
keccakAsString(value)
|
||||
).to.equal(result);
|
||||
).toEqual(result);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user