我尝试编写一个允许Ajax调用被嘲笑的规范.测试用例在Chrome和Firefox等浏览器上运行得非常好.但是当我在IE上运行测试用例(版本9,10)时,我遇到了一些问题.当使用jQuery Ajax进行正常的Ajax调用时会出现此问题.
我在IE中收到错误如下:
TypeError: Unable to get value of the property 'response': object is null or undefined.
我写的测试用例如下
describe("mocking ajax",function() {
beforeEach(function() {
jasmine.Ajax.install();
});
afterEach(function() {
jasmine.Ajax.uninstall();
});
it("specifying response when you need it",function() {
var doneFn = jasmine.createSpy("success");
var jqxhr = $.ajax({
url :"/any/service",success : function(data){
doneFn(data);
}
});
expect(doneFn).not.toHaveBeenCalled();
jasmine.Ajax.requests.mostRecent().response({
"status": 200,"contentType": 'text/plain',"responseText": 'awesome response'
});
expect(doneFn).toHaveBeenCalledWith('awesome response');
});
});
有关此问题的任何帮助表示赞赏.
提前致谢!
解决方法
你在用jasmine-ajax吗?在github repo上出现了一个问题似乎已经被最近的拉取请求修复了.
IE Issue jasmine-ajax