admin管理员组文章数量:1414944
i want to write a test for test createUser
.
i write this code :
const User = require("../src/Entite/User");
describe("Create User", () => {
it(" Save and Create User ", (done) => {
const addUser = new User({
name: "Kianoush",
family: "Dortaj",
});
addUser
.save()
.then(() => {
assert(!addUser.isNew);
done();
});
});
});
when i run the test use was created in database but it show me this error and test fail :
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (F:\Projects\Nodejs\MongooDB\test\create-user_test.js) at listOnTimeout (internal/timers.js:549:17) at processTimers (internal/timers.js:492:7)
whats the problem ? how can i solve that ??
i want to write a test for test createUser
.
i write this code :
const User = require("../src/Entite/User");
describe("Create User", () => {
it(" Save and Create User ", (done) => {
const addUser = new User({
name: "Kianoush",
family: "Dortaj",
});
addUser
.save()
.then(() => {
assert(!addUser.isNew);
done();
});
});
});
when i run the test use was created in database but it show me this error and test fail :
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (F:\Projects\Nodejs\MongooDB\test\create-user_test.js) at listOnTimeout (internal/timers.js:549:17) at processTimers (internal/timers.js:492:7)
whats the problem ? how can i solve that ??
Share Improve this question asked Jul 2, 2020 at 18:07 kianoush dortajkianoush dortaj 4519 silver badges28 bronze badges 1- Does this answer your question? In mocha testing while calling asynchronous function how to avoid the timeout Error: timeout of 2000ms exceeded – Dez Commented Jul 2, 2020 at 18:31
1 Answer
Reset to default 3Here a few solutions can be checked.
"scripts": {
"test": "mocha --timeout 10000" <= increase this from 1000 to 10000
},
#### OR ###
it("Test Post Request", function(done) {
this.timeout(10000); //add timeout.
});
Test-specific timeouts may also be applied, or the use of this.timeout(0)
to disable timeouts all together:
it('should take less than 500ms', function(done){
this.timeout(500);
setTimeout(done, 300);
});
If both do not work. Try this
const delay = require('delay')
describe('Test', function() {
it('should resolve', async function() {
await delay(1000)
})
})
Somehow the presence of the done argument in the async function breaks the test, even if it's not used, and even if done() is called at the end of the test.
本文标签:
版权声明:本文标题:javascript - Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" when using Mocha fo 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745192198a2646964.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论