Unit testing 具有多个外部API请求的单元测试express route controller
在我的单元测试中,我需要模拟一些http请求Unit testing 具有多个外部API请求的单元测试express route controller,unit-testing,express,nock,Unit Testing,Express,Nock,在我的单元测试中,我需要模拟一些http请求 const getDashboardData = (req, res) => { const activeListings = articlesLib.getLiveArticles(req.user.id) const soldThisMonthPromise = articlesLib.getSoldArticles(req.user.id, {}) const userDrafts = articlesLib.getDraft
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请求时,是否有任何工具模拟响应