我正在使用mocha运行单元测试,我想强制超时,如果函数超过30000,所以我设置了this.timeout(30000)。
为了验证它的工作,我在测试用例中放入了无限循环,即使超时了测试也没有返回。我希望这个测试在超时后停止执行。
以下是测试内容
it('should forcefully timeout',function(done) {
this.timeout(30000);
while(1) {
for(var i = 0; i < 10000; i++) {
if( i % 2 == 0 ) {
console.log("here");
for(var i=0; i < 10000; i++) {
if( i % 2 == 0 ) {
console.log("here1");
}
}
}
}
}
done();
})