timeout - PhantomJs超时

标签 timeout jasmine phantomjs

我使用 Jasmine 和 PhantomJS 来运行测试用例。

在我的典型测试用例中,我调用服务电话,等待响应并确认响应。

有些请求可能会在几秒钟内返回,有些可能需要一分钟才能返回。

当通过 PhantomJS 运行时,测试用例因应该需要一分钟的服务调用而失败(失败是因为尚未收到响应)。

有趣的是,通过 Firefox 运行时测试通过了。

我尝试查看 tcpdump,并且通过两个浏览器的请求的 header 相同,因此这看起来像是浏览器超时问题。

有人遇到过类似的问题吗?关于在哪里可以配置超时有什么想法吗?或者您认为问题出在其他方面?

最佳答案

啊 PhantomJS 的痛苦。

显然我使用的是 javascript 的 bind 函数,PhantomJS 不支持该函数。 这导致测试失败,从而导致某些全局变量的状态困惑(我的错),从而导致失败。

但根本原因是使用bind

解决方案:尝试从 https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/bind 获取一个用于 bind 的垫片

if (!Function.prototype.bind) {
  Function.prototype.bind = function (oThis) {
    if (typeof this !== "function") {
      // closest thing possible to the ECMAScript 5 internal IsCallable function
      throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
    }

    var aArgs = Array.prototype.slice.call(arguments, 1), 
        fToBind = this, 
        fNOP = function () {},
        fBound = function () {
          return fToBind.apply(this instanceof fNOP && oThis
                                 ? this
                                 : oThis,
                               aArgs.concat(Array.prototype.slice.call(arguments)));
        };

    fNOP.prototype = this.prototype;
    fBound.prototype = new fNOP();

    return fBound;
  };
}

关于timeout - PhantomJs超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16846506/

相关文章:

java - RxJava 中的超时

android.media.MediaCodec.finalize() 10 秒后超时

angular - 我正在尝试使用 jasmine 和 angular 测试来自服务的 api 请求,但没有成功

java - 如何修复 NoClassDefFoundError : CircularOutputStream error?

Elasticsearch 超时 true 但仍然得到结果

javascript - 延迟 for 循环内的 javascript 代码执行

javascript - CasperJS 在使用 sendKeys 时不上传文件

node.js - 如何将静态文件预加载或安装到 Highchart 的导出服务器中?

node.js - npm 安装 jasmine-jquery 失败

javascript - 如何将 $rootScope 注入(inject) AngularJS 单元测试?