Stubbing route callback render route status not found

♀尐吖头ヾ 提交于 2020-01-05 04:19:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!