0

My code looks like this,

const octokit = new Octokit({
    auth: process.env.auth,
});
const queries = JSON.stringify(event.queryStringParameters);
const repos = await octokit.request(`GET /repos/{org}/{repo}/tarball`);

I am able to mock the octokit object, but unable to mock this,

octokit.request(`GET /repos/{org}/{repo}/tarball`)
Jaragan Ittah
  • 36
  • 1
  • 2
  • I'd suggest you _don't_, don't mock what you don't own. Use something like MSW to stub the transport layer instead, I gave an example here https://stackoverflow.com/a/65627662/3001761. – jonrsharpe Jul 31 '21 at 20:34

1 Answers1

1

Was able to find the solution,

jest.mock('@octokit/rest')
const request = () => new Promise((resolve, reject) => {
  resolve({ status: 302, headers: { location: 'mock-url' } });
})
Octokit.mockImplementation(() => ({ request }))
Jaragan Ittah
  • 36
  • 1
  • 2