Javascript 未找到存根路由回调呈现路由状态
我有一条路线Javascript 未找到存根路由回调呈现路由状态,javascript,mocha.js,sinon,chai-http,Javascript,Mocha.js,Sinon,Chai Http,我有一条路线 app.get("/test", myControllers.controllerTest) controllerTest返回当前时间作为查询结果 我的路由测试文件 describe.("GET /test", () => { it("should return correct response", done => { sinon.stub(myControllers, "controllerTest").yields(null, {time
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
我错过了什么
更新
在中断回调时,我得到错误无法获取/route
,就像回调不存在一样。这与执行app.get('/test')
有人知道如何截取回调吗