如何解决NodeJs测试错误:超时超过2000ms
我正在测试多个响应,但总是以相同的错误消息结尾:
Error: Timeout of 2000ms exceeded. For async tests and hooks,ensure "done()" is called; if returning a Promise,ensure it resolves. (/this/file/path.js)
let invalid = 'something_invalid';
it('With valid appid',(done) => {
request(server).get(`/game/info/${valid}`)
.then((err,res) => {
let json = res.body;
expect(200);
expect(json.name).to.equal("Rust");
done();
}).catch(err => console.log(err))
});
响应为:
{
"name": "Rust","appid": 252490,"description": "The only aim in Rust is to survive - Overcome struggles such as hunger,thirst and cold. Build a fire. Build a shelter. Kill animals. Protect yourself from other players.","publishers": [
"Facepunch Studios"
],"price_text": "€33.99","platforms": {
"windows": true,"mac": true,"linux": false
},"likes": 374668
}
我到处都看过,但是解决问题的方法却解决不了。 对我在做什么错有任何想法吗?
解决方法
尝试在运行测试时设置更长的超时时间:
mocha --timeout 10000
或者在每个套件或每个测试中手动进行:
describe('...',function(){
this.timeout(10000);
it('...',function(done){
this.timeout(10000);
setTimeout(done,10000);
});
});
,
这不会等待10秒,如果响应在7秒后退出测试用例,请尝试此操作
it('With valid appid',(done) => {
request(server).get(`/game/info/${valid}`)
.then((err,res) => {
let json = res.body;
expect(200);
expect(json.name).to.equal("Rust");
done();
}).catch(err => console.log(err))
},10000);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。