Node.js 使用jest模拟请求时出现TypeError

Node.js 使用jest模拟请求时出现TypeError,node.js,unit-testing,jestjs,Node.js,Unit Testing,Jestjs,我对node比较陌生,在尝试使用jest模拟请求时遇到问题 如果要测试的文件具有require('request'),并且我尝试运行npm test,则会出现以下错误: FAIL __tests__/sum-test.js (0.291s) ● sum › it adds 1 + 2 to equal 3 - TypeError: The super constructor to `inherits` must have a prototype. at Object.exp

我对node比较陌生,在尝试使用jest模拟
请求时遇到问题

如果要测试的文件具有
require('request')
,并且我尝试运行
npm test
,则会出现以下错误:

FAIL  __tests__/sum-test.js (0.291s)
● sum › it adds 1 + 2 to equal 3
  - TypeError: The super constructor to `inherits` must have a prototype.
        at Object.exports.inherits (util.js:756:11)
        at Object.<anonymous> (node_modules/request/node_modules/http-signature/node_modules/sshpk/lib/private-key.js:44:6)
        at Object.<anonymous> (node_modules/request/node_modules/http-signature/node_modules/sshpk/lib/utils.js:16:18)
有人知道为什么会发生这种情况吗?

在测试文件中添加
jest.unmock('request')


当您需要文件中的某些内容时,Jest将模拟一个假的require对象。在这种情况下,request不是真正的请求。因此,请告诉jext not mock QUEST。

这对我很有效@Manu如果这对你有效,请接受这个答案。
{
  "name": "jesttest",
  "version": "1.0.0",
  "scripts": {
    "test": "jest"
  },
  "devDependencies": {
    "jest-cli": "^12.0.2"
  },
  "dependencies": {
    "request": "^2.72.0"
  }
}