-1

我的代码看起来像这样,

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

我能够模拟 octokit 对象,但无法模拟这个,

octokit.request(`GET /repos/{org}/{repo}/tarball`)
4

1 回答 1

1

能够找到解决方案,

jest.mock('@octokit/rest')
const request = () => new Promise((resolve, reject) => {
  resolve({ status: 302, headers: { location: 'mock-url' } });
})
Octokit.mockImplementation(() => ({ request }))
于 2021-08-01T21:51:26.660 回答