Convert tests to use jest (#7)
This commit is contained in:
@@ -0,0 +1 @@
|
||||
module.exports = require('@polkadot/dev/jest.config');
|
||||
Generated
+2437
-678
File diff suppressed because it is too large
Load Diff
+8
-7
@@ -27,16 +27,17 @@
|
||||
"scripts": {
|
||||
"build": "rimraf build && babel src --out-dir build --ignore *.spec.js",
|
||||
"check": "eslint src && flow check",
|
||||
"test": "cross-env NODE_ENV=test babel-istanbul cover _mocha 'src/*.spec.js' 'src/**/*.spec.js'"
|
||||
"test": "jest --coverage src"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/dev": "^0.1.7",
|
||||
"@polkadot/api-provider": "^0.1.3"
|
||||
"@polkadot/dev": "^0.2.2",
|
||||
"@polkadot/api-provider": "^0.1.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api-format": "~0.3.4",
|
||||
"@polkadot/jsonrpc": "~0.3.5",
|
||||
"@polkadot/util": "~0.5.2",
|
||||
"babel-runtime": "^6.26.0"
|
||||
"@polkadot/api-format": "~0.3.5",
|
||||
"@polkadot/jsonrpc": "~0.3.6",
|
||||
"@polkadot/util": "~0.5.4",
|
||||
"babel-runtime": "^6.26.0",
|
||||
"jest": "^21.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
+14
-15
@@ -1,8 +1,6 @@
|
||||
// ISC, Copyright 2017 Jaco Greeff
|
||||
|
||||
/* eslint-disable no-unused-expressions */
|
||||
|
||||
const sinon = require('sinon');
|
||||
/* global jest */
|
||||
|
||||
const isFunction = require('@polkadot/util/is/function');
|
||||
|
||||
@@ -11,6 +9,7 @@ const Api = require('./api');
|
||||
describe('Api', () => {
|
||||
let api;
|
||||
let provider;
|
||||
let sendSpy;
|
||||
|
||||
beforeEach(() => {
|
||||
provider = {
|
||||
@@ -18,33 +17,33 @@ describe('Api', () => {
|
||||
return Promise.resolve(params[0]);
|
||||
}
|
||||
};
|
||||
sinon.spy(provider, 'send');
|
||||
sendSpy = jest.spyOn(provider, 'send');
|
||||
api = new Api(provider);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
provider.send.restore();
|
||||
sendSpy.mockRestore();
|
||||
});
|
||||
|
||||
describe('constructor', () => {
|
||||
it('requires a provider', () => {
|
||||
expect(
|
||||
() => new Api()
|
||||
).to.throw(/Instantiate the Api/);
|
||||
).toThrow(/Instantiate the Api/);
|
||||
});
|
||||
|
||||
it('requires a provider with a send method', () => {
|
||||
expect(
|
||||
() => new Api({})
|
||||
).to.throw(/does not expose send/);
|
||||
).toThrow(/does not expose send/);
|
||||
});
|
||||
|
||||
it('sets up the chain interface', () => {
|
||||
expect(api.chain).to.be.ok;
|
||||
expect(api.chain).toBeDefined();
|
||||
});
|
||||
|
||||
it('sets up the state interface', () => {
|
||||
expect(api.state).to.be.ok;
|
||||
expect(api.state).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -72,12 +71,12 @@ describe('Api', () => {
|
||||
|
||||
describe('method expansion', () => {
|
||||
it('adds the specified methods to the interface', () => {
|
||||
expect(Object.keys(container)).to.deep.equal(['blah', 'bleh']);
|
||||
expect(Object.keys(container)).toEqual(['blah', 'bleh']);
|
||||
});
|
||||
|
||||
it('had function calls for the attached methods', () => {
|
||||
expect(isFunction(container.blah)).to.be.true;
|
||||
expect(isFunction(container.bleh)).to.be.true;
|
||||
expect(isFunction(container.blah)).toEqual(true);
|
||||
expect(isFunction(container.bleh)).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -86,7 +85,7 @@ describe('Api', () => {
|
||||
return container
|
||||
.blah()
|
||||
.catch((error) => {
|
||||
expect(error).to.match(/test_blah \(foo: Address\): Address/);
|
||||
expect(error.message).toMatch(/test_blah \(foo: Address\): Address/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -94,7 +93,7 @@ describe('Api', () => {
|
||||
return container
|
||||
.bleh(1)
|
||||
.catch((error) => {
|
||||
expect(error).to.match(/0 params expected, found 1 instead/);
|
||||
expect(error.message).toMatch(/0 params expected, found 1 instead/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -102,7 +101,7 @@ describe('Api', () => {
|
||||
return container
|
||||
.blah('0x123')
|
||||
.then(() => {
|
||||
expect(provider.send).to.have.been.calledWith('test_blah', [
|
||||
expect(provider.send).toHaveBeenCalledWith('test_blah', [
|
||||
'0x0000000000000000000000000000000000000123'
|
||||
]);
|
||||
});
|
||||
|
||||
+1
-3
@@ -1,11 +1,9 @@
|
||||
// ISC, Copyright 2017 Jaco Greeff
|
||||
|
||||
/* eslint-disable no-unused-expressions */
|
||||
|
||||
const Api = require('./index');
|
||||
|
||||
describe('index', () => {
|
||||
it('exports default Api', () => {
|
||||
expect(Api).to.be.ok;
|
||||
expect(Api).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
// ISC, Copyright 2017 Jaco Greeff
|
||||
|
||||
const chai = require('chai');
|
||||
const sinonChai = require('sinon-chai');
|
||||
|
||||
chai.use(sinonChai);
|
||||
|
||||
global.expect = chai.expect;
|
||||
@@ -1 +0,0 @@
|
||||
-r ./test/mocha.config
|
||||
Reference in New Issue
Block a user