Skip to content

Instantly share code, notes, and snippets.

@marcello3d
Created February 2, 2025 04:32
Show Gist options
  • Save marcello3d/4b49544899633d04c1b5db9b69b0954f to your computer and use it in GitHub Desktop.
Save marcello3d/4b49544899633d04c1b5db9b69b0954f to your computer and use it in GitHub Desktop.
nock back fetch bug
// Copyright 2025 Descript, Inc
import { back as nockBack } from 'nock';
import path from 'path';
describe('FetchTest', () => {
it('can do parallel fetches', async () => {
nockBack.fixtures = path.join(__dirname, '__nocks__');
const { nockDone } = await nockBack(`test.json`);
await Promise.all([fetch('https://api.github.com'), fetch('https://api.github.com')]);
nockDone();
});
});
FAIL unit src/actions/FetchTest.test.ts
FetchTest
✕ can do parallel fetches (232 ms)
● FetchTest › can do parallel fetches
TypeError: Body is unusable: Body has already been read
7 | nockBack.fixtures = path.join(__dirname, '__nocks__');
8 | const { nockDone } = await nockBack(`test.json`);
> 9 | await Promise.all([fetch('https://api.github.com'), fetch('https://api.github.com')]);
| ^
10 | nockDone();
11 | });
12 | });
at _Emitter.<anonymous> (../../node_modules/.pnpm/[email protected]/node_modules/nock/lib/recorder.js:265:35)
at _Emitter.<anonymous> (../../node_modules/.pnpm/[email protected]/node_modules/strict-event-emitter/src/Emitter.ts:88:23)
at emitAsync (../../node_modules/.pnpm/@[email protected]/node_modules/@mswjs/interceptors/src/utils/emitAsync.ts:23:20)
at ../../node_modules/.pnpm/@[email protected]/node_modules/@mswjs/interceptors/src/interceptors/fetch/index.ts:155:11
at async Promise.all (index 0)
at Object.<anonymous> (src/actions/FetchTest.test.ts:9:9)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 0.596 s, estimated 1 s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment