可以't为jasmine设置超时
Can't set timeout for jasmine
我已经尝试了这个答案中的所有解决方案,但没有一个对我有效。
我正在使用jasmine v2.3.2
和jasmine-core v2.3.4
当我做这个测试时:
jasmine.DEFAULT_TIMEOUT_INTERVAL= 999999;
describe('tests content controller', function(){
//...
fit('/content should return 200',function(done){
request(app)
.get('/content?type=script')
.set('Authorization', "bearer " + requestor.token)
.set('Accept', 'application/json')
.expect(200)
.end(function (err, res) {
if (err) done.fail(err);
expect(res.statusCode).toBe(200);
console.log('got here');
console.log(jasmine.DEFAULT_TIMEOUT_INTERVAL); //prints 30000
done();
})
},999999);
我在控制台上看到,请求只花了3000毫秒。我甚至看到了我的got here
日志。
显示超时的日志会打印出30000
,而不是像我所期望的那样打印999999
。
我也得到了一个失败的测试消息:
Message:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Stack:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
1 spec, 1 failure
Finished in 33.069 seconds
有一些初始设置导致了大约30秒的大部分延迟。应用程序必须连接到多个数据库,并在describe
中运行beforeAll
函数。
我怎样才能防止茉莉花这样不合时宜?
尝试在beforeAll
中设置jasmine.DEFAULT_TIMEOUT_INTERVAL
,因为每个it
块的超时间隔都会重置:
describe("testing timeout", function() {
beforeAll(function() {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 999999;
});
fit('should have custom timeout', function(){
console.log(jasmine.DEFAULT_TIMEOUT_INTERVAL); //prints 999999
});
})
此外,请记住,setTimeout在后台使用32位整数来存储延迟,因此超过此值的整数值将导致溢出。请参阅以下帖子:无限茉莉超时
相关文章:
- 如何设置html元素填充的动画
- 需要帮助设置json数组
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- 数组在递归方法中设置为null
- 如何在Bootstrap Modal中为动态点击生成的变量设置jade属性
- 测试iFrame的位置.href是在jasmine单元测试中设置的
- 为什么 Jasmine 在我设置 selectedIndex 时抱怨“试图分配给只读属性”
- 在jasmine ajax mock响应中设置响应头
- 设置 Jasmine & Karma 来测试 Angular
- 可以't为jasmine设置超时
- 设置Karma与jasmine一起运行测试,要求并做出反应
- 如何测试Jasmine设置代码
- 为jasmine添加固定装置/设置jasmine - jquery
- 如何设置Karma + Jasmine使用ES6模块
- Jasmine 2.0中无法设置回调时的异步测试
- Jasmine:在初始化时设置控制器属性,角度为1.5
- 如何使用Mimosa / Bower设置Jasmine js
- 有没有办法巩固'spy '在Jasmine测试中设置
- 在 Jasmine 中为 angularjs 设置全局变量
- 在Jasmine中是否有相应的NUnit' TestCaseSource设置?