Skip to content
Proyectos

Acerca de

Biblioteca para simular servidores HTTP y definir expectativas en Node.js

Sistemas e infraestructura

Cómo se miden estas cifras

Crecimiento de estrellas medido

in 24h
0
in 7 days
+2
in 15 days
+5
in 1 month
+11

Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.

README.md

Original

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.

Explorar proyectos relacionados

Cargando…