# @tapjs/nock

> a nock extension for tap

Latest version **6.3.13** (published 2026-11-03) · BlueOak-1.0.0 license · 0 weekly downloads

## Install

```sh
npm install @tapjs/nock
pnpm add @tapjs/nock
yarn add @tapjs/nock
bun add @tapjs/nock
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 6.3.13 |
| Published | 2026-11-03 |
| First published | 2023-08-04 |
| Weekly downloads | 0 |
| License | BlueOak-1.0.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | 20 \|\| >=22 |
| Dependencies | 3 |
| Unpacked size | 94.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2427 |
| Maintainers | ljharb, isaacs |
| Keywords | tapjs plugin, nock |

## Links

- npm: https://www.npmjs.com/package/@tapjs/nock
- Repository: https://github.com/tapjs/tapjs
- Homepage: https://github.com/tapjs/tapjs/tree/main/src/nock#readme
- Issues: https://github.com/tapjs/tapjs/issues
- npm.io page: https://npm.io/package/@tapjs/nock

## Dependencies (3)

- [nock](https://npm.io/package/nock.md) ^13.5.4
- [@tapjs/stack](https://npm.io/package/@tapjs/stack.md) 4.3.3
- [@tapjs/snapshot](https://npm.io/package/@tapjs/snapshot.md) 4.3.13

## Alternatives

- [pagerjs](https://npm.io/package/pagerjs.md) — 60 weekly downloads
- [whistle.savefor-mock](https://npm.io/package/whistle.savefor-mock.md) — 4 weekly downloads
- [@apigit/mock-engine](https://npm.io/package/@apigit/mock-engine.md) — 0 weekly downloads
- [devicemock](https://npm.io/package/devicemock.md) — 0 weekly downloads
- [@ruvector/agentic-synth-examples](https://npm.io/package/@ruvector/agentic-synth-examples.md) — 0 weekly downloads

## Recent versions

- 6.3.13 (latest) — 2026-11-03
- 3.0.0 (pre) — 2023-09-15
- 6.3.12 — 2026-09-03
- 6.3.11 — 2026-07-27
- 6.3.10 — 2026-05-15
- 6.3.9 — 2026-05-13
- 6.3.8 — 2026-05-01
- 6.3.7 — 2026-04-17
- 6.3.6 — 2026-04-15
- 6.3.5 — 2026-04-05
- 6.3.4 — 2026-02-20
- 6.3.3 — 2026-02-18
- 6.3.2 — 2026-02-18
- 6.3.1 — 2026-02-05
- 6.3.0 — 2025-12-01
- … 76 more at https://npm.io/package/@tapjs/nock/versions

## README

# `@tapjs/nock`

A [tap](https://node-tap.org) extension that integrates
[nock](https://github.com/nock/nock).

### Features

- `t.nock()`
  - automatically calls `nock.disableNetConnect()`
  - arguments are passed directly to `nock`, and the result from
    `nock` returned
  - asserts all nock scopes created within a test have been
    consumed
  - cleans only the nock scopes created within the current test,
    keeping nocks from parent tests
  - if no parent tests have nocks, calls
    `nock.enableNetConnect()` in teardown
- `t.nock.snapshot()`
  - when [snapshots are
    enabled](https://node-tap.org/plugins/snapshot/), sends real
    requests and records responses to a fixture
  - when snapshots are not enabled, loads fixture data and sets
    up `nock` scopes for you

### Usage

Load the `@tapjs/nock` plugin in your tap config.

For example, in `.taprc`:

```yaml
plugins:
  - @tapjs/nock
```

Or in `package.json`:

```json
{
  "tap": {
    "plugins": ["@tapjs/nock"]
  }
}
```

Then use it in your tests like so:

```ts
import t from 'tap'

t.test('sends a request', async t => {
  t.nock('https://registry.npmjs.org')
    .get('/')
    .reply(200, { hello: 'world' })

  const res = await fetch('https://registry.npmjs.org')
  t.equal(res.status, 200)
  const body = await res.json()
  t.same(body, { hello: 'world' })
})

// when snapshots are enabled, this test will send a real request
// and record the response
// when they are disabled, the recorded response will be
// automatically loaded into a nock scope, and the test will
// receive that response
// This requires that the @tapjs/snapshot plugin is enabled.
t.test('snapshots a request', async t => {
  t.nock.snapshot()

  const res = await fetch('https://registry.npmjs.org')
  t.equal(res.status, 200)
  const body = await res.json()
  t.match(body, { db_name: 'registry' })
})
```

You _may_ use it directly, though that is a bit more clunky,
because it won't be automatically applied to child tests, but it
can be good if you only need `nock` in a small number of tests.

```ts
import { plugin as tapNock } from '@tapjs/nock'
import t from 'tap'

t.test('sends a request', async t => {
  const tn = tapNock(t)
  tn.nock('https://registry.npmjs.org')
    .get('/')
    .reply(200, { hello: 'world' })

  const res = await fetch('https://registry.npmjs.org')
  t.equal(res.status, 200)
  const body = await res.json()
  t.same(body, { hello: 'world' })
})

// when snapshots are enabled, this test will send a real request
// and record the response
// when they are disabled, the recorded response will be
// automatically loaded into a nock scope, and the test will
// receive that response
// This requires that the @tapjs/snapshot plugin is enabled.
t.test('snapshots a request', async t => {
  const tn = tapNock(t)
  tn.nock.snapshot()

  const res = await fetch('https://registry.npmjs.org')
  t.equal(res.status, 200)
  const body = await res.json()
  t.match(body, { db_name: 'registry' })
})
```

## Credits

This plugin was originally developed by
[nlf](https://github.com/nlf) as the standalone extension
[@npmcli/tap-nock](https://github.com/npm/tap-nock), and the use
case was a major inspiration for tap's plugin eventual
architecture.

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