我正在使用Mocha来测试我的node js应用程序。无法覆盖该功能的错误块。下面是代码。
public getTaskSummaryByTaskId(req: Request, res: Response, next:
NextFunction) {
let taskId = parseInt(req.query['taskId'], 0);
new TasksManager().getTaskSummaryByTaskId(taskId).then(results => {
let data = results[0];
let taskList: ITaskSummary = {
Task: (data[0].length === 0 ? null : data[0][0]),
TaskWorkList: (data[1].length === 0 ? null : data[1]),
TaskAttachments: (data[2].length === 0 ? null : data[2]),
TaskAdditionalInfo: (data[3].length === 0 ? null : data[3])
};
return Api.ok(req, res, taskList);
}, err => {
next(err);
});
}
以下是我为上述函数调用的代码覆盖范围编写的测试用例。如何为上述调用覆盖“ err”块
it('Task Summary By TaskId', () => {
return chai.request(app).get(route + '/taskSummary')
.query({ taskId: 1000 })
.then(res => {
expect(res.body).to.have.property('Task');
expect(res.body).to.have.property('TaskWorkList');
expect(res.body).to.have.property('TaskAttachments');
expect(res.body).to.have.property('TaskAdditionalInfo');
expect(res).to.be.json;
expect(res.body).to.be.an('object');
});
});