当传递一个大的毫秒值时,我遇到了一些意想不到的行为setTimeout().例如,
setTimeout(some_callback, Number.MAX_VALUE);
Run Code Online (Sandbox Code Playgroud)
和
setTimeout(some_callback, Infinity);
Run Code Online (Sandbox Code Playgroud)
两者都导致some_callback几乎立即运行,好像我已经通过0而不是大量的延迟.
为什么会这样?
我已经尝试了这个答案中的所有解决方案,但它们都不适合我.
我正在使用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);
Run Code Online (Sandbox Code Playgroud)
我在控制台上看到请求只花了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 …Run Code Online (Sandbox Code Playgroud)