0

js), I want to test it normally using mocha and chai, but the API is having dependency with external service which I want to mock. Is it possible to mock that internal calls follow the below eg to make a clear picture:

describe('account Link', function() {
    it('should return with account status', async function(done) {
      nock('http://api.github.com', { allowUnmocked: true })
      .get('/users/AKGP')
      .reply(200, 
        {
          test: true
        });

     const options = {
       uri: 'http://localhost:3000/internal_api',
       body: {},
       headers: {
         'content-type': 'application/json'
       },
       method: 'POST',
       json: true
     }
     try {
      const res = await rp(options)
      console.log(res)
      done();
     } catch(err){
       console.log(err);
       done();
     }
    });
  });

// the nocked api is called internally and I am expecting to mock it (http://api.github.com)
2
  • what you have done should work. nock can mock the internal calls as well. Have you made sure that your request is matching else nock wouldn't mock. Commented Jan 16, 2020 at 13:14
  • Yes its same api calls
    – Ajay
    Commented Jan 17, 2020 at 5:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.