ECONNREFUSED 127.0.0.1:80 using fetch-mock-jest for /localRoute mock

2.7k views Asked by At

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

There are 2 answers

1
Sebastien Horin On

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?

1
wheresrhys On

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.