@springworks/test-harness v3.0.2
test-harness
Setup should and sinon with plugins.
- Add should to the global scope.
- Add sinon to the global scope.
- Install the should-sinon plugin.
- Install the should-http plugin.
Install
$ npm i -D @springworks/test-harnessUsage
Test-harness
Require @springworks/test-harness using the --require option when running tests with mocha.
$ mocha --require @springworks/test-harnessThe --require option can be added to a mocha.opts file.
Example mocha.opts file:
--ui bdd
--check-leaks
--recursive
--slow 200
--reporter spec
--compilers js:babel/register
--require @springworks/test-harnessCommonly used random identifiers
Require @springworks/test-harness/test-data-helper and call the
functions as needed. These have TypeScript definitions.
Example test file
No need to require should, sinon or any of the plugins.
const autorestoredSandbox = require('@springworks/test-harness/autorestored-sandbox');
const api_tester = require('@springworks/test-harness/api-tester');
describe('test-harness', () => {
const sandbox = autorestoredSandbox();
describe('globals', () => {
it('should expose should as a global', () => {
should.exist(should);
});
it('should expose sinon as a global', () => {
should.exist(sinon);
});
});
describe('asserting sinon fakes', () => {
it('should use the should-sinon plugin', () => {
const test_stub = sinon.stub().returns('hello');
test_stub().should.eql('hello');
test_stub.should.have.callCount(1);
});
});
describe('asserting promises', () => {
it('should use the should-promised plugin', () => {
return Promise.resolve().should.be.fulfilled();
});
});
describe('asserting http requests', () => {
it('should use the should-http plugin', () => {
({ statusCode: 200 }).should.have.status(200);
});
});
describe('run tests against static API', () => {
api_tester.configureStaticApi(data_store_api_static.createApiServer, config.get('test_helper.data_store_api.port'));
it('should be able to send request to static API and resolve without issues');
});
});7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago