3

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 ?

skyboyer
  • 22,209
  • 7
  • 57
  • 64
François Richard
  • 6,817
  • 10
  • 43
  • 78

2 Answers2

1

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.

wheresrhys
  • 22,558
  • 19
  • 94
  • 162
0

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?

Sebastien Horin
  • 10,803
  • 4
  • 52
  • 54