Перехват вызовов внешнего API в nodejs - PullRequest
0 голосов
/ 16 января 2020

js), я хочу протестировать это нормально, используя mocha и chai, но у API есть зависимость от внешнего сервиса, который я хочу смоделировать. Можно ли посмеяться над тем, чтобы внутренние звонки выполнялись, как указано ниже, например, чтобы получить четкую картину:

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)
...