Questions tagged [nock]

Nock is an HTTP mocking and expectations library for Node.js

Nock is an HTTP mocking and expectations library for Node.js

Nock can be used to test modules that perform HTTP requests in isolation.

For instance, if a module performs HTTP requests to a CouchDB server or makes HTTP requests to the Amazon API, you can test that module in isolation.

This does NOT work with Browserify, only node.js

Documentation

281 questions
4
votes
1 answer

How to ETIMEDOUT with nock and request library

How to force ETIMEDOUT with nock (https://github.com/node-nock/nock) and request? I tried following, where nock will delay response for 8000 milliseconds while timeout for request will be set to 5000 milliseconds, so i would expect to see ETIMEDOUT…
Srle
  • 10,366
  • 8
  • 34
  • 63
4
votes
2 answers

Mocking superagent post request with nock not matching

I cannot for the life of me get nock to work with a simple superagent post request. Here is both my superagent and nock configuration. superagent: request .post('https://test.com/api/login') .send({ email: 'test@test.com', password:…
ThinkingInBits
  • 10,792
  • 8
  • 57
  • 82
3
votes
1 answer

Is it possible to mock responses during a detox end-to-end test

I'm currently making a react-native mobile application. I try to test my login button and fields and want to test the logic of moving to the account screen upon login. Currently I got this as my testcase: import {clickAccountButton} from…
Julianvv
  • 100
  • 10
3
votes
1 answer

How to match a buffer request body with Mock Service Worker

I am currently using Nock and would like to replace it with Mock Service Worker. With Nock I am able to match the stringified request body with the provided buffer: const request = nock(hostname) .post('/api/instance',…
AmD
  • 399
  • 2
  • 12
3
votes
1 answer

nock multiple requests mocks

I am changing and endpoint in my express backend that would typically make 1 http request to a vendor's API to create a payment object in their system for a previously created account. The previously created account is currently created by sending a…
thehme
  • 2,698
  • 4
  • 33
  • 39
3
votes
1 answer

text() method not available in Blob

I am doing some Integration tests with jest & nock to test Axios interceptors chaining. In one of them, I am expecting to receive a Blob instance and according to this link, I should be able to use its text() method. My question is: Why is this…
fservantdev
  • 528
  • 8
  • 18
3
votes
1 answer

Nock: how to assert request wasn't made

When a request is made and wasn't mocked I get an error: Error: Nock: No match for request but that doesn't fail the test. Is there a way to make sure no mocked requests were made?
Ben
  • 871
  • 2
  • 9
  • 18
3
votes
2 answers

nockBack fails to record any fixtures

I cannot get nockBack to record any fixtures, although it should do that. My test code looks as follows: describe("#searchForProjects", function () { beforeEach(function () { nock.back.setMode("record"); this.con =…
D4N
  • 41
  • 3
3
votes
1 answer

Is there any way nock can work with puppeteer

I would like to use nock for mocking HTTP requests in puppeteer but for doing it nock should run in the same node process. Is there any solution or workaround for that? nock has great functionality that relevant also for e2e tests or scrapers
3
votes
1 answer

Nock - Invalid "extends" configuration value tslint error

I'm getting the below tslint error after i started using nock in my tests. Failed to load \node_modules\nock\types\tslint.json: Invalid "extends" configuration value - could not require "dtslint/dtslint.json". Review the Node lookup…
Mahendra R
  • 101
  • 2
  • 5
3
votes
1 answer

nock scope.isDone(): How to determine what expectation was not met?

I wish to mock testing an Dropbox API using nock. My issue is with scoping function .isDone(), which determines if the expectation were met. The console.log added to nock.post() is showing matching as true: matching…
Jeff
  • 1,917
  • 1
  • 25
  • 43
3
votes
1 answer

Nock does not intercept call to 3rd party

I am trying to automate some REST services using SuperTest. The service is a POST call, which internally calls another third party service GET method. I am trying to mock third party services to improve test efficiency and reduce test execution…
3
votes
1 answer

supertest mock with nock.back record mode not working

I have a nodejs service that when calling it's endpoint, does an http call to a service B. I'm adding an acceptance test to my service to test the integration. Using nock.back in dryrun mode works perfectly but when I set the mode to record, the…
Joan Vilà
  • 265
  • 5
  • 9
3
votes
1 answer

Nock Headers Authorization forbidden

I am trying to nock an axios request. I have successfully mocked the POST request, but it is sending an OPTIONS preflight request. However, I am getting the following error and not sure what to make of it. Error: Headers Authorization forbidden
timmyg13
  • 503
  • 1
  • 5
  • 15
3
votes
0 answers

Authorization header isn't mocked

thunk that makes async call buyerAction = (data = {}, cb) => (dispatch) => { console.log('x-access-token', authService.getAccessToken()); axios({ method: 'POST', url: `http://localhost:3001/api/manageUsers`, headers: { …
bikky barnwal
  • 173
  • 2
  • 11