我想为异步提取调用编写一个Jasmine测试。这就是我的测试目前的情况:
describe("async fetch call", function(){
it ("should contact server and call callback success", function(){
var server = sinon.fakeServer.create();
server.autoRespond = true;
server.respondWith([200, {'Content-Type': 'application/json'}, '{"collection":"coll","response":"resp", "options":"opts", "readyState":"1"}']);
var callback = {
success: jasmine.createSpy("success").and.callFake(function (){
expect(callback.success).toHaveBeenCalled();
}),
error: jasmine.createSpy("error")
};
session.getCompanies(callback);
server.restore();
});
});
函数session.getCompanies正在调用fetch命令。 我使用Jasmine 2.2.0和SinonJS。当我运行此测试时,期望被称为太晚了。如何让测试等到调用expect?