Javascript 即使状态为500,Chai也通过了测试用例

Javascript 即使状态为500,Chai也通过了测试用例,javascript,node.js,express,mocha.js,chai,Javascript,Node.js,Express,Mocha.js,Chai,我正在使用chai和mocha,chai-http为我的api运行测试用例。我返回500的响应,即使这样,我的测试用例也通过了 这是我的测试用例 describe('/POST saveBatch', () => { it('it should save the Batch', (done) => { chai.request(app) .post('/batches/saveBatch') .set('content-type

我正在使用chai和mocha,chai-http为我的api运行测试用例。我返回500的响应,即使这样,我的测试用例也通过了

这是我的测试用例

describe('/POST saveBatch', () => {
    it('it should save the Batch', (done) => {
        chai.request(app)
        .post('/batches/saveBatch')
        .set('content-type', 'application/x-www-form-urlencoded')
        .send({batch_id: 1})
        .end((err, res) => {
            expect(err).to.be.null;
           expect(res).to.have.status(200);
            done();
        });
    });
});
这是我的控制器

batchController.saveBatch=async(req,res)=>{
    let _value=await batchService.saveBatch(req.body);

    if(_value.error)
    {

        //throw new Error(_value.data);
      res.json({data:"Error Occurred"}).status(500);
    }

    else{
        res.json({data:"Success"}).status(200);
    }

}
我返回500状态,但它仍然显示我的测试用例要通过。
感谢您的帮助

您是否尝试使用console.log查看从批处理服务返回的“\u value”的实际值?因为我很确定你的控制器函数实际上没有输入你的
if(_value.error)
,否则它会在
expect(res).to.have.status(200)上失败