Gravity
Search…
Testing
Use Firelab by Gravity to run comprehensive end-to-end browser and integration tests.

Mocha Integration Tests

Gravity comes with a full suite of integration tests included in the toolbelt. You can run these to ensure your application functions as it should before releasing it.
Please set the SUPPORT_EMAIL variable in your environment before running tests as this email is used for testing.
1
// to start the tests, run:
2
gravity test
3
4
// or
5
npm test
Copied!
The testing suite uses mocha and chai, you can find boilerplate tests in the /test folder.

How Tests Work

A test calls the API endpoint and passes a data object. The response is then tested to ensure the correct status is returned and the returned data matches a specific format.
1
describe('POST /account', () => {
2
it ('should create a new paid account', done => {
3
4
config.account.paid.token = { id: 'tok_visa' };
5
6
chai.request(server)
7
.post('/api/account')
8
.send(config.account.paid)
9
.end((err, res) => {
10
11
res.should.have.status(200);
12
res.body.token.should.be.a('string');
13
res.body.plan.should.eq(config.account.paid.plan);
14
res.body.subscription.should.eq('active');
15
process.env.token = 'Bearer ' + res.body.token;
16
17
// cleanup
18
delete config.account.paid.token;
19
done();
20
21
});
22
}).timeout(config.timeout);
23
});
Copied!
To add your own tests, simply create a new test script and import it to the run.js file (executed by the toolbelt). Use the example above as a template to get you started.
You can also use npm test
Last modified 6mo ago