This repository includes tools to be able to use the ABE format with a Node.js Express server. In particular we aim to support the testing of API routes to check that the responses match those expected created mocks which follow the ABE format.
npm install abe-express --save-dev
In order to use abe-express
you will use this within your current testing setup
### Header test
This is a helper which will run a test against your API ensuring that the header response matches that of your mock. In order to do this, it will match the status
code of your mock, it will also test the expected Content-type
matches (this is only done if your mock contains the Content-type
in it's headers).
var abeExpress = require('abe-express'),
myApp = require('../app.js'),
mock = require('../mocks/example.json'),
example = 'OK';
it('Should return a 200 status code', function (done) {
abeExpress.header(myApp, mock, example, done);
});
### Full test
This is a helper which will run all tests against your API, ensuring that the body response of your API matches that of your mock. It will also run the tests against the header
.
var abeExpress = require('abe-express'),
myApp = require('../app.js'),
mock = require('../mocks/example.json'),
example = 'OK';
it('Should return a 200 status code and body', function (done) {
abeExpress.full(myApp, mock, example, done);
});
This will be your Express app in which the route has been attached to in which you want to test.
This will be the full ABE-Spec
mock in which you are wanting to test against.
This is the key
within the examples
object of your mock.
This is the function which your testing system will pass within a it
test, to tell your test that it has completed.