我正在尝试为数据库播种以进行单元测试。
下面是 seed.js
文件:
.......
const app = require('./app')
const db = app.get('db')
const saveUsersToDB = (done) => {
db.User.bulkCreate(users)
.then(() => (done))
}
module.exports = {saveUsersToDB};
我的 app.test.js
文件:
.......
const expect = require('expect')
const request = require('supertest')
const {saveUsersToDB} = require('./seed/seed');
before(saveUsersToDB)
当我运行下面的测试是我得到的错误:
Express listening on port 3000!
1) "before all" hook: saveUsersToDB
0 passing (2s)
1 failing
1) "before all" hook: saveUsersToDB:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
npm ERR! Test failed. See above for more details.
我认为返回 .then(() => (done))
就足够了?我做错了什么?
最佳答案
默认情况下,Mocha 测试有 2 秒的超时时间(这意味着测试需要在 2 秒内完成)。
您可以按如下方式增加它(以毫秒为单位):
this.timeout(5000); // this test can take up to 5 seconds
关于javascript - Mocha : Error Timeout of 2000ms exceeded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40902493/