【发布时间】:2020-04-17 13:39:37
【问题描述】:
所以 fetch-mock-jest 是基于 fetch-mock 的(它不是 jest-fetch-mock..)
https://www.npmjs.com/package/fetch-mock-jest
http://www.wheresrhys.co.uk/fetch-mock/
我遇到的问题是:
// inside my test file
fetchMock.restore().mock('https://someSiteOnTheInternet.com', someResponse)
// inside my tested file
fetch('https://someSiteOnTheInternet.com').then(...)
上述方法有效,但一旦我尝试本地路线,它不再有效
// inside my test file
fetchMock.restore().mock('/myProxy', someResponse)
// inside my tested file
fetch('/myProxy').then(...)
这个('/myProxy')将失败并出现错误:
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
知道我在这里做错了什么吗?
【问题讨论】:
-
你检查端口是否已经被保留了吗?
-
嗯是的 localhost 没有被使用...
-
不是 localhost 作为一个整体,我的意思是端口
80,因为它可以在进行测试期间被正在运行的进程使用。 -
不,我跑了 lsof -nP -iTCP:80 | grep 听; 80 端口未使用
标签: jestjs fetch-mock