All Questions
5 questions
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 &...
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 ...
0
votes
1
answer
809
views
nock handles fetch req but does not prevent http call
I am using nock to intercept a fetch call to https://www.youtube.com/oembed?url=https://youtu.be/m4hklkGvTGQ . Like so:
it(`properly responds to YouTube URL ${url}`, async () => {
nock('https:/...
3
votes
1
answer
4k
views
Using nock to test POST request in async action creator
I am using nock to mock my asynchronous thunk action creators. Everything works as expected for GET requests, but I haven't been able to make a POST request work. I have read everything I can find ...
5
votes
1
answer
2k
views
Nock intercepts request but returns empty object
I'm using mocha as the testing framework and I'm trying to mock up a DELETE request that uses fetch against an end point that returns HTTP status code 204.
Here is the test code:
it('should logout ...