How can I complete some async task before starting test
test('setup', function (t) {
//complete some async task here then do the test. In my case test are getting executed before the async task is done.
});
test('GET /hello', function (t) {
request(app)
.get('/hello')
.query({name:'asfd'})
.expect(200)
.expect('Content-Type', /json/)
.end(function (err, res) {
t.end();
});
});
Use t.plan()
Is there anything like before in mocha?
@mustafamamun no, there's definitely not, but since it's just JS, you can do this:
test('blah', function (t) {
t.plan(1);
someAsyncBeforeLogic(function () {
somethingAsync(function (error, result) {
if (error) {
t.fail(error);
} else {
t.ok(result);
}
});
});
});