0

How can I mock octokit library in jest

import { Octokit } from '@octokit/rest';

The code I'm using is:

const { data: entity } = await octokit.rest.repos.getContent({owner, repo, path, ref})
Akash
  • 75
  • 1
  • 8

1 Answers1

0

Here is one way you can do it, it is my preferred way (Disclaimer: I created most of the JavaScript Octokit).

When you instantiate Octokit, you can pass a custom fetch implementation

const octokit = new Octokit({ request: { fetch } })

Create the fetch instance using https://github.com/wheresrhys/fetch-mock.

Here is an example: https://github.com/octokit/core.js/blob/5ffb0f86acecf137e195befae505147e08e08fe4/test/request.test.ts

Gregor
  • 2,325
  • 17
  • 27