mardi 17 avril 2018

nodejs nock's isDone() always return true

I am using node-nock. My test codes:

it('should hit callback', function() {
  const api = nock('http://test.com').post('/test', '*').reply(200, 'hello, testers.');
  const j = {
    id: 'b5a4bf6c-f66f-4d9d-884a-70f658a826xxx',
    url: 'http://example.com',
    data: {},
    version: 1
  };
  const options = {
    url: '...',
    json: true,
    body: j,
    method: 'post'
  };
  request(options, function(error, response, body) {
      assert.isTrue(api.isDone(), 'callback hit');
    });
});

In fact, after request(options, function(error, response, body), some data is posted to http://example.com/test/. why api.isDone() is true? I may miss something.

Any comments welcomed. Thanks

Aucun commentaire:

Enregistrer un commentaire