我有一条路线
app.get("/test", myControllers.controllerTest)
controllerTest 返回当前时间作为查询结果
我的路线测试文件
describe.("GET /test", () => {
it("should return correct response", done => {
sinon.stub(myControllers, "controllerTest").yields(null, {time:'fake-time'});
app = require("../../server");
chai
.request(app)
.get("/test")
.then(res => {
expect(res.status).to.equal(200);
expect(myControllers.controllerTest).to.have.been.calledOnce;
done();
})
.catch(err=>{
done(err)
});
});
});
测试失败,它告诉我在我存根回调后路由返回 404 而不是 200。
请注意,使用spy
而不是stub
工作。但在这种情况下,我需要使用stub
我错过了什么?
更新
存根回调时,出现错误cannot get /route
,就像回调不存在一样。和执行一样app.get('/test')
任何人都知道如何存根回调?