我使用 Jasmine 和 PhantomJS 来运行测试用例。
在我的典型测试用例中,我拨打服务电话,等待响应并确认响应。
有些请求可能会在几秒钟内返回,有些请求可能需要一分钟才能返回。
当通过 PhantomJS 运行时,测试用例因服务调用而失败,该调用应该需要一分钟(失败是因为尚未收到响应)。
有趣的是,在 Firefox 中运行时测试通过了。
我尝试查看 tcpdump,并且通过两个浏览器的请求的标头相同,因此这看起来像是浏览器超时问题。
有人遇到过类似的问题吗?关于在哪里可以配置超时有什么想法吗?或者您认为问题出在其他方面?
PhantomJS 的痛苦啊。
显然我正在使用javascriptbind
PhantomJS 不支持的功能。
这导致测试失败,导致某些全局变量的状态混乱(我的错),从而导致失败。
但根本原因是使用bind
.
解决方案:尝试获取垫片bind
像这样从https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/bind https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/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;
};
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)