# @octokit/fixtures

> Fixtures for all the octokittens

Latest version **23.1.2** (published 2026-04-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @octokit/fixtures
pnpm add @octokit/fixtures
yarn add @octokit/fixtures
bun add @octokit/fixtures
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; has provenance; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 23.1.2 |
| Published | 2026-04-07 |
| First published | 2017-09-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 1.1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 109 |
| Author | Gregor Martynus |
| Maintainers | octokitbot |

## Links

- npm: https://www.npmjs.com/package/@octokit/fixtures
- Repository: https://github.com/octokit/fixtures
- Homepage: https://github.com/octokit/fixtures#readme
- Issues: https://github.com/octokit/fixtures/issues
- npm.io page: https://npm.io/package/@octokit/fixtures

## Dependencies (4)

- [nock](https://npm.io/package/nock.md) ^13.0.0
- [lodash](https://npm.io/package/lodash.md) ^4.18.1
- [json-diff](https://npm.io/package/json-diff.md) ^1.0.0
- [url-template](https://npm.io/package/url-template.md) ^3.0.0

## Recent versions

- 23.1.2 (latest) — 2026-04-07
- 23.1.1 — 2024-04-09
- 23.1.0 — 2024-04-03
- 23.0.0 — 2024-03-04
- 22.0.7 — 2024-01-25
- 22.0.6 — 2022-11-09
- 22.0.5 — 2022-11-08
- 22.0.4 — 2022-07-19
- 22.0.3 — 2022-06-24
- 22.0.2 — 2021-09-24
- 22.0.1 — 2021-09-24
- 22.0.0 — 2021-06-13
- 21.5.0 — 2021-05-28
- 21.4.0 — 2021-05-05
- 21.3.9 — 2021-03-26
- … 132 more at https://npm.io/package/@octokit/fixtures/versions

## README

# fixtures

> Fixtures for all the octokittens

![Test](https://github.com/octokit/fixtures/workflows/Test/badge.svg)

Records requests/responses against the [GitHub REST API](https://developer.github.com/v3/)
and stores them as JSON fixtures.

- [Usage](#usage)
  - [fixtures.mock(scenario)](#fixturesmockscenario)
  - [fixtures.get(scenario)](#fixturesgetscenario)
  - [fixtures.nock](#fixturesnock)
- [How it works](HOW_IT_WORKS.md)
- [Contributing](CONTRIBUTING.md)
- [License](#license)

## Usage

Currently requires node 8+

### fixtures.mock(scenario)

`fixtures.mock(scenario)` will intercept requests using [nock](https://www.npmjs.com/package/nock).
`scenario` is a String in the form `<host name>/<scenario name>`. `host name`
is any folder in [`scenarios/`](scenarios/). `scenario name` is any filename in
the host name folders without the `.js` extension.

```js
const https = require("https");
const fixtures = require("@octokit/fixtures");

fixtures.mock("api.github.com/get-repository");
https
  .request(
    {
      method: "GET",
      hostname: "api.github.com",
      path: "/repos/octokit-fixture-org/hello-world",
      headers: {
        accept: "application/vnd.github.v3+json",
      },
    },
    (response) => {
      console.log("headers:", response.headers);
      response.on("data", (data) => console.log(data.toString()));
      // logs response from fixture
    },
  )
  .end();
```

For tests, you can check if all mocks have been satisfied for a given scenario

```js
const mock = fixtures.mock("api.github.com/get-repository");
// send requests ...
mock.done(); // will throw an error unless all mocked routes have been called
mock.isDone(); // returns true / false
mock.pending(); // returns array of pending mocks in the format [<method> <path>]
```

`mock.explain` can be used to amend an error thrown by nock if a request could
not be matched

```js
const mock = fixtures.mock("api.github.com/get-repository");
const github = new GitHub();
return github.repos
  .get({ owner: "octokit-fixture-org", repo: "hello-world" })
  .catch(mock.explain);
```

Now instead of logging

```
Error: Nock: No match for request {
  "method": "get",
  "url": "https://api.github.com/orgs/octokit-fixture-org",
  "headers": {
    "host": "api.github.com",
    "content-length": "0",
    "user-agent": "NodeJS HTTP Client",
    "accept": "application/vnd.github.v3+json"
  }
}
```

The log shows exactly what the difference between the sent request and the next
pending mock is

```diff
 Request did not match mock:
 {
   headers: {
-    accept: "application/vnd.github.v3"
+    accept: "application/vnd.github.v3+json"
   }
 }
```

### fixtures.get(scenario)

`fixtures.get(scenario)` will return the JSON object which is used by [nock](https://www.npmjs.com/package/nock)
to mock the API routes. You can use that method to convert the JSON to another
format, for example.

### fixtures.nock

`fixtures.nock` is the [nock](https://github.com/node-nock/nock) instance used
internally by `@octokit/fixtures` for the http mocking. Use at your own peril :)

## License

[MIT](LICENSE.md)

---
_Source: https://npm.io/package/@octokit/fixtures · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
