Tape: Initiate async task before test

Created on 20 Jun 2017  路  3Comments  路  Source: substack/tape

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();
    });
});
question

All 3 comments

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);
      }
    });
  });
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

javajosh picture javajosh  路  5Comments

dcousens picture dcousens  路  3Comments

justingosan picture justingosan  路  8Comments

shaunlebron picture shaunlebron  路  4Comments

jimkang picture jimkang  路  3Comments