Update tests to use jest (#11)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
build/
|
||||
coverage/
|
||||
docs/
|
||||
node_modules/
|
||||
tmp/
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
Utility methods to convert to and from `BN` objects
|
||||
|
||||
- (bnFromHex)[#bnFromHex] Creates a BN.js bignumber object from a hex string.
|
||||
- (bnToHex)[#bnToHex] Creates a hex value from a BN.js bignumber object.
|
||||
- [bnFromHex](#bnFromHex) Creates a BN.js bignumber object from a hex string.
|
||||
- [bnToHex](#bnToHex) Creates a hex value from a BN.js bignumber object.
|
||||
|
||||
## bnFromHex
|
||||
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
|
||||
Utility methods to convert to and from `Buffer` objects
|
||||
|
||||
- (bufferFromHex)[#bufferFromHex] Creates a Buffer object from a hex string.
|
||||
- (bufferToHex)[#bufferToHex] Creates a hex value from a Buffer object.
|
||||
- [bufferFromHex](#bufferFromHex) Creates a Buffer object from a hex string.
|
||||
- [bufferToHex](#bufferToHex) Creates a hex value from a Buffer object.
|
||||
|
||||
## bufferFromHex
|
||||
|
||||
|
||||
+3
-3
@@ -2,9 +2,9 @@
|
||||
|
||||
Internal utilities to create and test for hex values
|
||||
|
||||
- (hexAddPrefix)[#hexAddPrefix] Adds the `0x` prefix to string values.
|
||||
- (hexHasPrefix)[#hexHasPrefix] Tests for the existence of a `0x` prefix.
|
||||
- (hexStripPrefix)[#hexStripPrefix] Strips any leading `0x` prefix.
|
||||
- [hexAddPrefix](#hexAddPrefix) Adds the `0x` prefix to string values.
|
||||
- [hexHasPrefix](#hexHasPrefix) Tests for the existence of a `0x` prefix.
|
||||
- [hexStripPrefix](#hexStripPrefix) Strips any leading `0x` prefix.
|
||||
|
||||
## hexAddPrefix
|
||||
|
||||
|
||||
+8
-8
@@ -2,14 +2,14 @@
|
||||
|
||||
Type checking utilities
|
||||
|
||||
- (isBN)[#isBN] Tests for a `BN` object instance.
|
||||
- (isBuffer)[#isBuffer] Tests for a `Buffer` object instance.
|
||||
- (isFunction)[#isFunction] Tests for a `function`.
|
||||
- (isHex)[#isHex] Tests for a hex string.
|
||||
- (isInstanceOf)[#isInstanceOf] Tests for a instance of a class.
|
||||
- (isNumber)[#isNumber] Tests for a JavaScript number.
|
||||
- (isString)[#isString] Tests for a string.
|
||||
- (isUndefined)[#isUndefined] Tests for a `undefined` values.
|
||||
- [isBN](#isBN) Tests for a `BN` object instance.
|
||||
- [isBuffer](#isBuffer) Tests for a `Buffer` object instance.
|
||||
- [isFunction](#isFunction) Tests for a `function`.
|
||||
- [isHex](#isHex) Tests for a hex string.
|
||||
- [isInstanceOf](#isInstanceOf) Tests for a instance of a class.
|
||||
- [isNumber](#isNumber) Tests for a JavaScript number.
|
||||
- [isString](#isString) Tests for a string.
|
||||
- [isUndefined](#isUndefined) Tests for a `undefined` values.
|
||||
|
||||
## isBN
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
Convenience functions for values from @polkadot/jsonrpc
|
||||
|
||||
- (jsonrpcSignature)[#jsonrpcSignature] Returns a string representation of the method with inputs and outputs.
|
||||
- [jsonrpcSignature](#jsonrpcSignature) Returns a string representation of the method with inputs and outputs.
|
||||
|
||||
## jsonrpcSignature
|
||||
|
||||
|
||||
+3
-3
@@ -2,9 +2,9 @@
|
||||
|
||||
Create Keccak256 values as hex, string & buffer output
|
||||
|
||||
- (keccakAsBuffer)[#keccakAsBuffer] Creates a keccak Buffer from the input.
|
||||
- (keccakAsHex)[#keccakAsHex] Creates a keccak hex string from the input.
|
||||
- (keccakAsString)[#keccakAsString] Creates a keccak string from the input.
|
||||
- [keccakAsBuffer](#keccakAsBuffer) Creates a keccak Buffer from the input.
|
||||
- [keccakAsHex](#keccakAsHex) Creates a keccak hex string from the input.
|
||||
- [keccakAsString](#keccakAsString) Creates a keccak string from the input.
|
||||
|
||||
## keccakAsBuffer
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
module.exports = require('@polkadot/dev/jest.config');
|
||||
Generated
+2562
-404
File diff suppressed because it is too large
Load Diff
+4
-6
@@ -27,14 +27,12 @@
|
||||
"build": "npm run build:js && npm run build:md",
|
||||
"build:js": "rimraf build && babel src --out-dir build --ignore *.spec.js",
|
||||
"build:md": "polkadot-dev-build-docs",
|
||||
"check": "npm run check:lint && npm run check:flow",
|
||||
"check:flow": "flow check",
|
||||
"check:lint": "eslint src",
|
||||
"test": "cross-env NODE_ENV=test babel-istanbul cover _mocha 'src/*.spec.js' 'src/**/*.spec.js'"
|
||||
"check": "eslint src && flow check",
|
||||
"test": "jest --coverage src"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/dev": "^0.1.7",
|
||||
"@polkadot/jsonrpc": "^0.3.5"
|
||||
"@polkadot/dev": "^0.2.2",
|
||||
"@polkadot/jsonrpc": "^0.3.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-runtime": "^6.26.0",
|
||||
|
||||
@@ -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