get*_*kin 5 integration-testing mocha.js node.js chai supertest
我正在测试多个响应,但总是得到相同的错误消息:
\n\n\nRun Code Online (Sandbox Code Playgroud)\nError: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/this/file/path.js)\n
let invalid = 'something_invalid';\n\n it('With valid appid', (done) => {\n request(server).get(`/game/info/${valid}`)\n .then((err, res) => {\n\n let json = res.body;\n\n expect(200);\n expect(json.name).to.equal("Rust");\n done();\n }).catch(err => console.log(err))\n });\nRun Code Online (Sandbox Code Playgroud)\n其中响应是:
\n{\n "name": "Rust",\n "appid": 252490,\n "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.",\n "publishers": [\n "Facepunch Studios"\n ],\n "price_text": "\xe2\x82\xac33.99",\n "platforms": {\n "windows": true,\n "mac": true,\n "linux": false\n },\n "likes": 374668\n}\nRun Code Online (Sandbox Code Playgroud)\n我到处都找过了,但问题的解决方案从未解决它。\n知道我做错了什么吗?
\n运行测试时尝试设置更长的超时:
mocha --timeout 10000
Run Code Online (Sandbox Code Playgroud)
或者在每个套件或每个测试中手动:
describe('...', function(){
this.timeout(10000);
it('...', function(done){
this.timeout(10000);
setTimeout(done, 10000);
});
});
Run Code Online (Sandbox Code Playgroud)