Sinon Fake server not auto responding

*爱你&永不变心* 提交于 2019-12-10 20:23:39

问题


Hi I am testing a collection using fetch, when I call it there is no answer from the fake server only after calling server.response I get the desired result.

Why is that ?

My code

  beforeEach( function() {
    server = sinon.fakeServer.create();
    server.autoRespond = true;
    colhedoraList = new ColhedoraList();
  });

.
.
.
    var spy       = sinon.spy(colhedoraList, 'parse');

    server.respondWith("GET", "getColhedoraInfo",
      [200, {"Content-Type": "application/json"},
      '[{"id":"1","talhaoAtual":1,"posicionamentos":[{"lat":-23.9317401,"lng":-50.2210379,"elevadorLigado":true,"horario":"2012-09-21T11:27:58Z"},{"lat":-23.931544,"lng":-50.2161884,"elevadorLigado":true,"horario":"2012-09-21T11:28:02Z"}]}]']);

    colhedoraList.fetch({add: true});
    server.respond();
    expect(spy).toHaveBeenCalled();
    expect(spygmaps).toHaveBeenCalledTwice();
    expect(colhedoraList.get(1).get('talhaoAtual')).toEqual(1);    <<< ALL EXPECTS FAIL, If I don't call respond().

回答1:


If you are using mock timers (sinon.useFakeTimers) anywhere in the spec, that might stop the autoresponder from working. The addRequest method creates a timeout inside which the request is actually responded to. The default wait time is 10ms.



来源:https://stackoverflow.com/questions/12601587/sinon-fake-server-not-auto-responding

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