您好,我正在使用 fetch 测试一个集合,当我调用它时,只有在调用 server.response 后,假服务器才没有应答,我得到了所需的结果。
这是为什么 ?
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().
如果您使用模拟计时器(sinon.useFakeTimers
)规范中的任何位置,这可能会阻止自动应答器工作。这addRequest
方法创建一个超时,在该超时内实际响应请求。默认等待时间为 10 毫秒。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)