草庐IT

getItemInfo

全部标签

javascript - 为什么我的 jest.mock 中的 Promise reject() 会转到 then() 而不是 catch()?

我有两个文件,getItemInfo.js进行API调用,getItemInfo.test.js是相应的Jest测试文件。在测试文件中,我正在模拟由Node模块request-promise触发的http调用。问题在第二个代码块上,被*********包围。基本上为什么reject()错误仍然会在第二个单元测试中进入then()block?//getItemInfo.jsconstrp=require('request-promise');constgetItemInfo=(id)=>{constroot='https://jsonplaceholder.typicode.com/po