Skip to main content
Filter by
Sorted by
Tagged with
2 votes
1 answer
50 views

Why I am getting undefined while testing redux actions? [closed]

describe('Fetch robots action success', () => { it('handle request robot action success', async () => { const store = mockStore(); const mockApiData = [ { id: 1, ...
miogway27202224's user avatar
2 votes
0 answers
67 views

Is there a way to verify order of HTTP calls?

I am using the Nock library for mocking HTTP calls, with Jest as the testing framework. I am loading mock calls from a json file. Tests work fine, but I want to make sure certain calls happen before ...
Amir Rachum's user avatar
  • 79.3k
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
2 votes
1 answer
559 views

How do I unit test TanStack's queryClient

I'm trying to unit test Tanstack's queryClient and I am able to test queries and components, but not sure how I would go about testing the queryCache and mutationCache inside of the queryClient and to ...
beeboop's user avatar
  • 41
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
1 vote
0 answers
332 views

How Can I Use nock with react-query in a React 18 Project for Testing?

I am trying to test a custom hook that uses react-query for data fetching in a React 18 project. The API call is mocked using nock, but I am facing issues: the result.current remains undefined, and ...
Michael Luo's user avatar
2 votes
1 answer
248 views

Nock JS mocking tool produces error `Right-hand side of 'instanceof' is not an object`

I am trying to use this tool called Nock JS https://www.npmjs.com/package/nock with a Next JS, React demo app tested using Cypress • Next JS 13.4 • Cypress 12.17.1 • React 18.2 e2e/homepage.cy.js ...
Jason FB's user avatar
  • 5,840
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
3 votes
1 answer
1k views

How to implement Code Coverage in a cypress environment where NextJS is build while running the tests?

We would like to add code coverage to a setup where we use cypress and nextjs. In our cypress config we build nextJs using next() to mock the backend requests inside nextjs. The cypress.config.ts ...
Lars Flieger's user avatar
  • 2,504
0 votes
1 answer
852 views

nock does not intercept follow-up calls when using axios-retry

In short: When doing normal calls, nock works perfectly But when testing a request that triggers axios-retry, nock fails when the first retry attempt happens (based on logging) Does nock support ...
Juha Untinen's user avatar
  • 1,856
0 votes
1 answer
254 views

React Native Test : Nock and Testing Library

I am trying to do screen testing with react native while mocking the api responses with Nock. After a call to the api my component is supposed to display some text fields. It works on the app but I ...
Antoine Grenard's user avatar
0 votes
1 answer
447 views

How do I do a Regex path match for a POST request with Nock.js?

I am trying to chain some requests in Nock with Regex matching on the path. All of the examples I see of Regex path matching are get requests. How do I do this properly? Is the below right? nock('...
Boris K's user avatar
  • 3,580
0 votes
2 answers
470 views

nock not setting the authorization header in react

Trying to mock the headers of authorization bearer token and few other headers in nock but nock is erroring out Nock: No match for request. It works without the headers and reqheaders though... Axios ...
Explorer's user avatar
  • 155
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
1 answer
3k views

Error: Nock: No match for request - but request is correct

I'm trying to write a mock test for the spotify web api authorize endpoint. I have the following code for nock: nock("https://accounts.spotify.com/") .post("/api/token", { ...
Grieze's user avatar
  • 53
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
0 votes
1 answer
719 views

HTTP interceptors (nock, msw) not working in Github Actions but work locally

I've tried a basic API test using two different libs - nock and msw - and both of them work locally. However, when running in Github Actions, they both fail with the same error: nock: FAIL src/...
Juha Untinen's user avatar
  • 1,856
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
4 votes
1 answer
2k views

Nock - Get number of calls performed to fetch

I've got a React custom hook that tries to avoid repeated calls to a URL. This is done by storing in state the isLoading prop, which is set to true whenever the fetch method is called, and is set to ...
Unapedra's user avatar
  • 2,363
2 votes
1 answer
312 views

Wrong count execution times of Sinon Spy

I have a major function that call 3 other functions. I want to test if those 3 function were called. myController.ts import axios from 'axios'; export async function functionOne() { console.log('...
PlayHardGoPro's user avatar
0 votes
1 answer
731 views

issue with nock isDone returning false

I have the following react test: ... const API_ADDR = "http://localhost:8000"; test("correct response recieved", () =>{ const {getByText,getByPlaceholderText} = render(<...
rogue_particle's user avatar
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
0 answers
830 views

Why these mocks are not resetting?

I am making app with Nextjs and Jest and React Testing Library for testing. I use nock for mock axios responses. My tests: axios.defaults.adapter = require('axios/lib/adapters/http'); describe('...
CubeStorm's user avatar
  • 138
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 votes
1 answer
653 views

nock not able to match all path segments for specific string

I tried several approach to match this specific pattern of the url: https://app.launchdarkly.com/sdk/goals/123123123 so the 123123123 will be always changing.also for some reason its making a OPTION ...
ey dee ey em's user avatar
  • 8,583
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
0 votes
1 answer
905 views

How do you nock with aws-sdk-js credentials required in requests?

I have jest unit tests using nock to intercept and return mock responses. I then re-run these during the integration test phase without nock so that it tests with the actual aws api and resources. ...
Chip's user avatar
  • 1,559
3 votes
1 answer
3k views

How do I use Nock to disable all external API requests during testing?

I'm testing a codebase that makes external requests to multiple APIs. How do I ensure that a request is never made to one of these APIs during testing? I already plan to use Nock for mocking responses,...
Nathan Arthur's user avatar
3 votes
1 answer
2k views

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 ...
Julianvv's user avatar
  • 108
2 votes
1 answer
1k views

Jest + Nock: How to fail a test if a non-mocked request is made?

I have a test that is passing. However, I actually want it to fail because Nock is complaining about an API call that I have not mocked. console.error node_modules/@testing-library/react/dist/act-...
bigpotato's user avatar
  • 27.4k
2 votes
1 answer
14k views

Jest and HTTP mocking with nock

I was trying to write my first ever Jest test for an endpoint in my Next.js App and this test always passes, no matter, how I try to 'break' it. Which makes me think, I did all wrong. Here is my api/...
Katharina Schreiber's user avatar
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
4 votes
1 answer
12k views

Typescript - Record<string, any> to Object

I have a Record<string, any> and would like to convert it to an object. I get this type unfortunately by Nock, so I can't change it though. But to continue working with it, I need an object. ...
Lukas Bauer's user avatar
1 vote
1 answer
414 views

Nock: nock.load does not work as expected

I am trying to load a JSON file that contains a mock response with the Nock function: nock.load(filePath). Oddly, the test fails with error: TypeError: nockDefs.forEach is not a function If I ...
Taslim Oseni's user avatar
  • 6,245
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
2 votes
0 answers
855 views

Nock fails to intercept requests in tests, but only in --coverage mode

I recently upgraded some packages in a previously-working app and found that changes in Jest made a bunch of tests fail after the upgrade, but ONLY in --coverage mode. All my Redux API action tests ...
rg_'s user avatar
  • 421
0 votes
0 answers
1k views

Request Headers Causing ' Nock: No Match For Request'

Notable Tools I'm also using: React; Express.JS as my APi. Output of Error: onsole.error pending mocks: ["GET http://localhost:5000/api/medias","GET http://localhost:5000/api/watching&...
Matthew Francis's user avatar
5 votes
1 answer
3k views

Mocking API calls with Detox and Nock

I'm trying to mock API calls from Detox tests and nothing seems to be working. Nock in theory would do exactly what I want but there when I run my tests with nock debugging it isn't seeing any of the ...
Derrick Neier's user avatar
0 votes
2 answers
7k views

"Error: Nock: No match for request" How to quickly understand what doesn't match?

I often face this error (Error: Nock: No match for request) using Nock, but I find it hard to quickly understand what doesn't match in order to adjust. I used to use nock(apiUrl).persist().log(console....
A Mehmeto's user avatar
  • 1,969
1 vote
1 answer
2k views

TypeError: nock(...).persist(...).log is not a function

I am trying to get more info on why my nock mock is not right, but I can't make the persist().log() work. Here is the test : it("should delete online absentee bid given its id", () => { ...
A Mehmeto's user avatar
  • 1,969
3 votes
1 answer
1k views

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) ...
AmD's user avatar
  • 499

1
2 3 4 5 6