SINON假服务器未自动响应

Sinon Fake server not auto responding(SINON假服务器未自动响应)

本文介绍了SINON假服务器未自动响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在使用FETCH测试一个集合,当我调用它时,只有在调用服务器之后才会有来自伪服务器的响应。Response我得到了所需的结果。

为什么?

我的代码

  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().

推荐答案

如果您在规范中的任何位置使用模拟计时器(sinon.useFakeTimers),这可能会阻止自动响应器工作。addRequest方法创建一个超时,在该超时内实际响应请求。默认等待时间为10毫秒。

这篇关于SINON假服务器未自动响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:SINON假服务器未自动响应

基础教程推荐