Skip to content
nockPublic

About

HTTP server mocking and expectations library for Node.js

Topics

Resources

Code of conduct

Contributing

Stars

13.1k stars

Watchers

87 watching

Forks

Latest commit

Β 

History

2,244 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Nock

npm Backers on Open Collective Sponsors on Open Collective

Nock is an HTTP mocking and expectations library for Node.js. Test code that makes HTTP requests in isolation, without depending on a live service.

Website | Getting started | API reference | Contributing

Install

pnpm install --save-dev nock

See the installation guide for other package managers.

Quick start

import assert from 'node:assert/strict'
import nock from 'nock'

const scope = nock('https://api.github.com')
  .get('/repos/atom/atom/license')
  .reply(200, { license: { key: 'mit', name: 'MIT License' } })

const response = await fetch('https://api.github.com/repos/atom/atom/license')
assert.equal(response.status, 200)
assert.deepEqual(await response.json(), {
  license: { key: 'mit', name: 'MIT License' },
})
scope.done()

Nock intercepts the request and returns the configured response. scope.done() asserts that the expected request was made. Interceptors are consumed after one matching request by default; see the guide to repeating mocks for other options.

Documentation

Visit nockjs.dev for the full documentation, guides, and API reference.

Contributing

Thanks for wanting to contribute! Take a look at our Contributing Guide for notes on our commit message conventions and how to run tests.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Contributors

Thanks goes to these wonderful people (emoji key):

Pedro Teixeira
Pedro Teixeira

πŸ’» 🚧
n30n0v
n30n0v

πŸ’»
Richard Littauer
Richard Littauer

🚧 πŸ’» πŸ“
Ian Walker-Sperber
Ian Walker-Sperber

πŸ’»
Ivan Erceg
Ivan Erceg

πŸ’» 🚧
Paul Melnikow
Paul Melnikow

πŸ’» 🚧
Gregor Martynus
Gregor Martynus

πŸ’» 🚧 πŸ’Ό πŸ’΅ πŸ“
Hutson Betts
Hutson Betts

πŸ’΅
Jonas Lilja
Jonas Lilja

πŸ’΅ πŸ’»
Benjamin Ki
Benjamin Ki

πŸ’΅
Chad Fawcett
Chad Fawcett

πŸ’΅
Laurence Dougal Myers
Laurence Dougal Myers

πŸ’»
SΓ©bastien Van Bruaene
SΓ©bastien Van Bruaene

πŸ’» ⚠️
Aras Abbasi
Aras Abbasi

πŸ’» ⚠️ 🚧
Saryev Rustam
Saryev Rustam

πŸ’» ⚠️
Michael Solomon
Michael Solomon

🚧 πŸ’» πŸ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

License

MIT

Copyright (c) 2011–2019 Pedro Teixeira and other contributors.

About

HTTP server mocking and expectations library for Node.js

Topics

Resources

Code of conduct

Contributing

Stars

13.1k stars

Watchers

87 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages