【发布时间】:2018-02-18 15:04:15
【问题描述】:
在我的express 应用程序中,我声明这样的请求处理程序(此处简化):
export const CreateProduct = async (req, res, next) => {
try {
// ProductModel is a sequelize defined model
const product = await ProductModel.create(req.body)
res.send(product)
} catch (err) {
// I have raygun setup as the error handler for express
// in this example, it will finally return 500
next(err)
}
}
然后像这样使用它:
import { CreateProduct } from './create_product'
export const ProductRouter = express.Router()
ProductRouter.post('/', CreateProduct)
但是,在运行我的测试时,nyc/istanbul 会抱怨 9 行是 Uncovered Line (在我的示例中,它是 next(err) 函数),我该如何模拟我的例子有错误吗?
【问题讨论】:
标签: node.js async-await mocha.js istanbul supertest