Javascript 摩卡咖啡&x27;每个吊钩前';错误消息
在测试失败之前,我收到以下消息 下面是我的一段代码Javascript 摩卡咖啡&x27;每个吊钩前';错误消息,javascript,node.js,testing,mocha.js,Javascript,Node.js,Testing,Mocha.js,在测试失败之前,我收到以下消息 下面是我的一段代码 before(function(done) { function afterListening() { customFormats(ZSchema); done(); } if (app.server.listening) return afterListening(); app.on('listening', afterListening); }); describe('/a1/{exampleID}',
before(function(done) {
function afterListening() {
customFormats(ZSchema);
done();
}
if (app.server.listening) return afterListening();
app.on('listening', afterListening);
});
describe('/a1/{exampleID}', function() {
describe('get', function() {
it('should respond with 200 Return an array of shelter...', function(done) {
/*eslint-disable*/
var schema = {
"type": [
"object",
"null"
],
"properties": {
"meta": {
"type": [
"object",
"null"
],
"properties": {
"resource": {
"type": [
"string",
"null"
],
"description": "fully qualified URL call"
},
"version": {
"type": [
"string",
"null"
],
"description": "version of API being called"
},
"response": {
"type": [
"integer",
"null"
],
"format": "int32",
"description": "status code"
},
"required": [
"version",
"resource"
]
}
}
};
/*eslint-enable*/
api.get('/a1/example/64442')
.set('Content-Type', 'application/json')
.expect(200)
.end(function(err, res) {
if (err) return done(err);
validator.validate(res.body, schema).should.be.true;
done();
});
});
});
});
错误
1) 示例“每个”挂钩之前:
错误:超时超过200毫秒。确保正在执行done()回调
在这次测试中被调用。
在空。(lib/runnable.js:170:19)
只有在我的机器上运行测试用例时,才会出现此错误。如果我在另一台机器上运行相同的测试用例,则测试用例通过。为什么会这样,看到这样很奇怪
请帮忙 你能和我们分享一下你的经验吗?这样我们就可以帮助你了 不看的话,可能是因为你与任何你正在连接的东西的连接没有及时响应或者根本没有响应 可能需要检查与单元测试连接的位置的连接(很可能是数据库,因为它位于
beforeach()
中,beforeach()
不需要在其中调用done()
)
将超时时间增加到10秒左右。如果没有出现数据库错误,则连接速度较慢。如果即使在10秒时仍出现超时错误,则可能根本没有连接。当您未按预期返回承诺时,通常会收到超时错误 Done是同一版本的较旧实现,但不再是必需的。如果您使用的是最新版本的Mocha,您应该能够返回承诺,而不是调用Done() 以下是自1.18.0版以来与默认Mocha集成的-的详细信息 您应如何返还承诺的示例:
it("should be fulfilled with 5", function () {
return promise.should.become(5);
});
在beforeach的情况下-实现应如下所示:
beforeEach(() => {
const {col1, comments} = mongoose.connection.collections;
return col1.drop(() => {
// Do something after collection is dropped
});
});
请注意在beforeach中执行的操作返回。我们需要查看您的代码,了解两台机器之间差异的更多细节。