3
votes

So fetch-mock-jest is based on fetch-mock (it's not jest-fetch-mock..)

https://www.npmjs.com/package/fetch-mock-jest

http://www.wheresrhys.co.uk/fetch-mock/

The problem I have is:

// inside my test file
fetchMock.restore().mock('https://someSiteOnTheInternet.com', someResponse)

// inside my tested file
fetch('https://someSiteOnTheInternet.com').then(...)

The above is working but as soon as I try a local route it's not working anymore

// inside my test file
fetchMock.restore().mock('/myProxy', someResponse)

// inside my tested file
fetch('/myProxy').then(...)

This one ('/myProxy') will fail with the error :

console.error node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/virtual-console.js:29
  Error: Error: connect ECONNREFUSED 127.0.0.1:80

Any idea what am I doing wrong here ?

2
Did you check if the port is already reserved ?Ahmad Shaarawi
hmm yes localhost is not used ...François Richard
not localhost as a whole, I meant port 80, as it could be used by a running process during making the test.Ahmad Shaarawi
no I ran lsof -nP -iTCP:80 | grep LISTEN ; port 80 is not usedFrançois Richard

2 Answers

1
votes

you can set DEBUG=fetch-mock* before running your tests and that will give a lot of output to show what's going on in fetch-mock's internals.

0
votes

You may have a conflict with docker, is your front dockerized? do you have docker running for your back-end? can you stop docker/restart your machine and try running only your front without docker?