在我的单元测试中,我需要模拟一些 http 请求。
const getDashboardData = (req, res) => {
const activeListings = articlesLib.getLiveArticles(req.user.id)
const soldThisMonthPromise = articlesLib.getSoldArticles(req.user.id, {})
const userDrafts = articlesLib.getDrafts(req.user.id)
return Promise.all([activeListings, soldThisMonthPromise, userDrafts])
.then((data) => {
res.render(`${__dirname}/home`, {
viewData: data
})
})
}
router.get('/', getDashboardData)
articleLib 的每个请求都有相同的 url,但 uri 不同。我想用 nock 模拟它,但它不支持对同一个基本 url 进行多个模拟。当检测到给定的http请求时,是否有任何工具可以模拟响应?