Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
0 answers
48 views

nock is not intercepting HTTPS request to Keyclaok

I have been struggling in the last two days to figure out what is not working well with my nock setup. Description: I work with node environment and express as the application server. The ...
Gavriel's user avatar
  • 51
0 votes
1 answer
138 views

Context is undefined in Apollo RESTDataSource

While upgrading from Apollo v2 to v3, I'm trying to make some external API calls to an auth server. Currently, I'm using nock to intercept the requests inside of a unit test. The GET request keeps ...
abeauchamp's user avatar
0 votes
1 answer
632 views

How to fix TS nock library not intercepting my API call?

I am using node 18 in my Typescript code and nock library https://www.npmjs.com/package/nock for tests. I have a simple class which makes fetch call to one endpoint and want to test it by mocking the ...
Kristi Jorgji's user avatar
1 vote
0 answers
169 views

How to mock 3rd party API calls in next.js integration tests?

I am calling OpenAI APIs from my next routes, I can intercept browser requests using nock library like below, but it won't mock server-side API calls since I am not calling OpenAI API from the browser ...
Visrut's user avatar
  • 631
2 votes
0 answers
152 views

Intercepting and redirecting an SSE request to a proxy server

I have a script, and I need to intercept and redirect a request to a proxy server. const originalDestination = 'http://localhost:3004'; const newDestination = 'http://localhost:3005'; // proxy In my ...
voice's user avatar
  • 880
0 votes
1 answer
3k views

Mocking data with nock in playwright test

I'm writing my first Playwright Screenshot-test for a node application. The application makes serverside api requests and I want to mock the api responses so that my test becomes stable, predictable ...
Drkawashima's user avatar
  • 9,654
1 vote
1 answer
1k views

Nock not mocking requests on Nextjs and Cypress

In some pages, we use getInitialProps that makes a request on the backend side to call an external endpoint. On the CI/CD machine we can´t call this other endpoint so we want to mock that endpoint. Im ...
Frankusky's user avatar
  • 1,083
4 votes
3 answers
8k views

How do I mock Node.js fetch HTTP requests/responses in Node 18?

I am using the new (as of version 18) Node.js "fetch" API to perform HTTP requests e.g. const response = await fetch(SOMEURL) const json = await response.json() This works, but I want to &...
Glynn Bird's user avatar
  • 5,627
1 vote
0 answers
346 views

Mocha and Nock error - Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called;

I am getting an error when I am using Nock twice in my unit tests. It seems like I am using Nock incorrectly. The first test passes but the second one has an error: Error: Timeout of 2000ms exceeded. ...
cam's user avatar
  • 251
0 votes
1 answer
216 views

Is it possible to reuse a nock object?

I am using nock for testing HTTP Endpoints and I don't want to define the headers and baseURL multiple times. Is it problematic to do something like this? const serviceNock = nock('https://my-service....
user246766's user avatar
1 vote
1 answer
475 views

supertest headers not working on node 16 but working on node 14

I have the following dependency versions supertest: 6.2.4 nock: 13.2.9 express: 4.17.1 nock: 13.2.9 Now this the works fine in node v14 but not in node v16 . Any suggestions as to why this could be ...
Rupam Roy's user avatar
  • 113
2 votes
0 answers
297 views

Cypress publicPath not supported with percy and nock

I'm getting an issue where I am trying to add percy to my Cypress tests using nock and webpack 5. Based on a solution found here, I tried to set the publicPath to an empty string, but with no ...
usr4896260's user avatar
  • 1,497
5 votes
1 answer
461 views

How to use nock in order to mock Firebase/Firestore in NodeJS?

I have a REST API which written in NodeJS. The REST API gets a file and information and then uploads the file to the drive and stores the information inside my Firebase/Firestore DB. I'm trying to ...
vesii's user avatar
  • 3,090
0 votes
1 answer
8k views

How to send multiple response using nock if there is no request body

I am calling a streaming api http://dummy-streaming-api/customer-details which accepts post requests and sends some data. It does not require any request body. I want to mock the response using nock ...
Biswambar's user avatar
1 vote
1 answer
1k views

Mock Injected Twilio Service in Unit Testing Nest.js

I have a problem with overriding provider/setup module testing in nest.js application for testing. Module file: smsModule.ts: import { TwilioService } from './twilio/twilio.service'; import { ...
MoTra's user avatar
  • 37
1 vote
0 answers
222 views

How to do integration test with chai for internal and nock for external api call

I have an app for Slack Interactivity Handling, what I'd like to do is just to receive webhook from the slack button and update the message via Slack API. I use express on my server, and core https ...
Fadel Trivandi Dipantara's user avatar
2 votes
1 answer
466 views

is there a way to nock an array of endpoints?

I want to abstract the client API responses from the tests and I'm trying to come up with a helper for that, for example: class MockedClientApi { constructor() { this.nock = nock('https://...
balexandre's user avatar
1 vote
1 answer
1k views

change the response for single request among multiple request in nock

I have using express and trying to create an API for testing I used nock so i make a get request whose response I don't want to change after that i want to do put request and want to change the ...
Akshay Vashishtha's user avatar
2 votes
2 answers
2k views

How to await until nock is called

I'm not sure if nock is supporting awaiting or notifying using callback / event-emitter when the interceptor is called. For example: const scope = nock(config.research.url) .post(...
Stav Alfi's user avatar
  • 13.9k
4 votes
3 answers
2k views

Fail test if a network request is made (using Nock)

I have logic that conditionally makes a network request, how can I, using Nock, make a test that would fail if a network request is made? Basically asserting that 0 calls to an endpoint was made.
per_jansson's user avatar
  • 2,189
0 votes
1 answer
3k views

Nock is not intercepting request if it runs multiples test in certain order

I'm creating some unit test for my endpoint. This endpoint will fetch data from an external API and send diff responses depending on finding a certain item on that data fetched or if there is an ...
ZhEd's user avatar
  • 1
4 votes
2 answers
689 views

How do I ignore certain domains from being records with nock.back?

I am using nock.back as part of mocha tests in my project. Even though I have setup nock.enableNetConnect, nock.back still records outgoing calls to the domain. const nock = require('nock') const path ...
akshah123's user avatar
  • 778
5 votes
1 answer
345 views

npm module function interception. specifically base module 'dns'

import DNS from 'dns' DNS.resolveTxt('test-website.com', (err, addresses) => { console.log(err, addresses); }) Above would be an example usage of how the node resolves a web address. I want ...
gatsbyz's user avatar
  • 1,075
1 vote
1 answer
1k views

Testing basic async http request in Node with Got, Nock & Chai

I am trying to figure out why my unit test is not working correctly. It seems that the external network request is made despite my using Nock to intercept my http request. I have a very basic getUser ...
cjashwell's user avatar
  • 609
1 vote
1 answer
8k views

Nock headers - Error: Nock: No match for request

Here's my example code for some reason Nock is failing for me as it can't match the URL when headers are added, when commenting the code like below the test passes. I can't figure out why nock doesn't ...
sam's user avatar
  • 113
0 votes
1 answer
988 views

How to match a binary buffer request body with Nock?

I am new at Node/TypeScript and write a simple script to learn the language. I am using nock for tests to check my http post requests with RequestBodyMatcher. Currently, it's dummy (see below). Now I ...
Michael's user avatar
  • 42k
0 votes
1 answer
344 views

nodejs nock http get always returns 503

I want to use nock for testing some http calls but it always retunrs 503 service unavailable describe('BASIC API AUTH TESTS', function() { 'use strict'; before(async () => { if (!nock....
Gobliins's user avatar
  • 4,016
1 vote
1 answer
2k views

Nock is not working with multiple test cases with same method

If I comment the first test case then second test works fine. If I run this test file. It gives 400 status which is the the status of first test case. How I can run the both test cases. I also added ...
MK12's user avatar
  • 491
0 votes
0 answers
730 views

Is there any way to mock a variable inside a function?

The code works like this let getToken = await apiCall(); apiCall() calls a few internal functions and populates getToken variable with a token. The problem is, in my tests, I can't seem to populate ...
user3019802's user avatar
0 votes
0 answers
728 views

return Readable mock from needle using nock - twitter filtered stream test

I've been trying for a few hours now and I'm still struggling how to properly test my connection to twitter filtered stream. This is how my class I want to test looks like: import { injectable } from '...
matewilk's user avatar
  • 1,301
1 vote
1 answer
710 views

How to mock HTTP2 server in node js

Is there a way or any NPM library to Mock Http2 server. Usually I use Nock for mocking http server but it seems Nock doesn't support Http2
saketh's user avatar
  • 813
0 votes
1 answer
755 views

(Nodejs Nock) Is there a cleaner way to simulate a response that changes with time in Nock

I know that nock allows for queueing mocks for the same endpoint like I have here: nock('https://example.test') .get('/') .delayConnection(400) .reply(200, MockApiResponses.proccessing) //response on ...
josh's user avatar
  • 1
0 votes
2 answers
245 views

Nock unexpected Token being caused by typescript?

I am running nock like this, inside my ts file: nock('https://example.test').post('/submit').reply(200,{ "status": "Invalid", "message": "Invalid Request&...
josh's user avatar
  • 1
3 votes
2 answers
1k views

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("...
D4N's user avatar
  • 41
1 vote
0 answers
141 views

Does nock work with nodes multi threaded Cluster module?

I have an application which uses NodeJs Cluster module to fork multiple processes of the app, each of these process send out post request to an endpoint which i want to nock. Now i understand that ...
Cameron Newby's user avatar
3 votes
1 answer
657 views

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 ...
Guy Serfaty's user avatar
0 votes
1 answer
447 views

promise await timeout exceeded

i got this following code inside a async function. when i am calling the function i am getting stuck after the await statement. i already checked my nock address for http req mocking and it is the ...
Dev93's user avatar
  • 103
0 votes
1 answer
253 views

Does async/await handle uncaught rejection errors differently?

In the following code block (example #1), expect(this.req.headers["user-agent"]).to.equal("BOOM") throws error and test fails. describe("http.get with headers", () => { it("should return ...
sunknudsen's user avatar
  • 7,190
0 votes
1 answer
636 views

Using nock to make a request made from a docker container?

My end-to-end tests are ran against a local docker environment of a micro service I'm testing, I want to mock out a request made via that docker environment from the end-to-end test but it just doesn'...
James Nixon's user avatar
1 vote
0 answers
329 views

Nock, Async/Await, Bitbucket: Intercept does not return before Chai begins assertion

I have an endpoint that makes an external API call. //outside.js const createTicket = async () => { try{ const someOptions = { /*stuff here*/} results = await rp.post('https://...
fishcakesAndCoffee's user avatar
1 vote
0 answers
624 views

Nock throws a no match for request when using Promise.race

I'm writing a test for some code that will use Promise.race to bring back a result from a graphql service that is on (could be on) multiple servers. I've used Nock to mock the request, which works ...
Jarede's user avatar
  • 3,488
0 votes
1 answer
349 views

Mocking LUIS response with LuisRecognizer not working

I am trying to mock calls to LUIS via nock, which uses the LuisRecognizer from botbuilder-ai. Here is the relevant information. The bot itself is calling LUIS and getting the result via const ...
billoverton's user avatar
  • 2,875
0 votes
0 answers
288 views

Intercepting an external API calls in nodejs

js), I want to test it normally using mocha and chai, but the API is having dependency with external service which I want to mock. Is it possible to mock that internal calls follow the below eg to ...
Ajay's user avatar
  • 23
6 votes
3 answers
5k views

Disable a single nock scope immediately to re-setup a mocked URL

Using nock, is there a way to disable a single nock scope? I've been struggling with some tests that set up nocks of the same URL as some other tests. They both run fine separately, but when run in ...
JHH's user avatar
  • 9,255
1 vote
1 answer
3k views

Nock interceptors chaining, second mock ignored

A simple example of a mocking chain of requests with nock. const request = require('request-promise'); module.exports = () => { const URL1 = 'https://my.host.com/a/b/c/d'; ...
Vasyl's user avatar
  • 236
1 vote
2 answers
698 views

Mocking Puppeteer Network Requests in SUT

Does anyone know how to mock network requests that Puppeteer makes when it is used as part of the system under test (but NOT to run the test)? For example, the system under test uses puppeteer to ...
Steven Musumeche's user avatar
0 votes
2 answers
926 views

How can I test a route with nock and request-promise when the url contains single quotes?

I am trying to test an API call using nock + request-promise and I am getting an error because the routes don't match. The issue appears to be that the API's url contains single quotes, and request-...
Jim Moody's user avatar
  • 798
0 votes
0 answers
191 views

Test using Nock in a scheduleJob

I'm getting a problem with test the http request in a scheduleJob node. Well, I've changed the crontime to run every second as suggested here for easier testing. The problem is, I don't think the Nock ...
mile's user avatar
  • 3
0 votes
1 answer
422 views

How to add extension function to nock.Scope

I am using nock in an angular/typescript server-side application's unit tests. I have a complex set of requests that get made often, and I would like to re-use the same set of nock requests for ...
KbCb's user avatar
  • 19
3 votes
1 answer
12k views

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 ...
Jeff's user avatar
  • 1,869