I use Mocha and Supertest to create tests for Node.js and Express apps. To use Supertest, I make my app in app.js a module, require it and Supertest(Supertest as a variable called request, the app as a variable called app), and create some code like this:
request(app)
.get('/')
.expect(200)
.end(function(error){
if(error) throw error;
console.log('Done');
});
It works, but it isn’t very readable on console. To solve this, I use Mocha:
describe('Requests to the root path'),function(){
it('Returns 200 status code',function(done){
request(app)
.get('/')
.expect(200,done);
});
});
Now my tests are readable. I run them with mocha “test file goes here”.
Leave A Comment