问题
I have a route
app.get("/test", myControllers.controllerTest)
The controllerTest returns current time as result to query
my route test file
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)
});
});
});
The test fails at it tells me route returned 404 instead of 200 after I stub the callback.
note that using spy
instead of stub
works. But in this case, i need to use stub
What am I missing?
UPDATE
When stubbing the callback, I get error cannot get /route
, It's like the callback doesnt exist. it's same as executing app.get('/test')
Anyone have any idea how to stub the callback?
来源:https://stackoverflow.com/questions/58209419/stubbing-route-callback-render-route-status-not-found