问题描述
我正在测试多个响应,但总是以相同的错误消息结尾:
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);