【问题标题】:Jasmine mock ajax calls not working in IEJasmine 模拟 ajax 调用在 IE 中不起作用
【发布时间】:2014-06-13 20:35:47
【问题描述】:

我尝试编写一个允许模拟 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');
 });

});

感谢您提供有关此问题的任何帮助。 提前致谢!

【问题讨论】:

  • 你能提供一个 jsfiddle 版本,它可以在 chrome 中运行,而不是在上述版本的 ie 中运行吗?

标签: javascript jquery internet-explorer tdd jasmine


【解决方案1】:

你在使用 jasmine-ajax 吗?在 github repo 上出现了一个关于此的问题,似乎已通过最近的 pull request 得到修复。

IE Issue jasmine-ajax

【讨论】:

  • 我认为这个问题是由 Tiger 提出的 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多