Nock 13.x → 14.x
Nock 14 adds support for intercepting Node.js native fetch and drops support for Node.js versions earlier than 18. See the v14.0.0 release notes.
Requirements
Nock 14 requires Node.js >=18. Upgrade Node before upgrading Nock if your project uses an older version.
Install Nock 14 with your package manager:
sh
npm install --save-dev nock@14Native fetch Support
Nock 14 can intercept Node.js native fetch requests as well as requests made through Node's HTTP APIs. Existing fetch calls can now be tested with Nock interceptors:
js
import nock from 'nock'
const scope = nock('https://api.example.test')
.get('/users')
.reply(200, [{ id: 1, name: 'Ada' }])
const response = await fetch('https://api.example.test/users')
const users = await response.json()
scope.done()If your tests need a real network request, configure Nock's network-connect rules explicitly. See Network Controls.
Verify the Upgrade
- Run the test suite on Node.js 18 or later.
- Add or update tests that use native
fetchto confirm those requests are intercepted. - Check integrations that expect
fetchto bypass Nock; Nock 14 now intercepts it.
For the next major upgrade, see Nock 14.x to 15.x.