我想弄清楚在所有測試運行後刪除數據庫和關閉連接的功能。在哪裏刪除數據庫並關閉所有使用摩卡測試之後的連接
這裏是我的嵌套的測試:
//db.connection.db.dropDatabase();
//db.connection.close();
describe('User', function(){
beforeEach(function(done){
});
after(function(done){
});
describe('#save()', function(){
beforeEach(function(done){
});
it('should have username property', function(done){
user.save(function(err, user){
done();
});
});
// now try a negative test
it('should not save if username is not present', function(done){
user.save(function(err, user){
done();
});
});
});
describe('#find()', function(){
beforeEach(function(done){
user.save(function(err, user){
done();
});
});
it('should find user by email', function(done){
User.findOne({email: fakeUser.email}, function(err, user){
done();
});
});
it('should find user by username', function(done){
User.findOne({username: fakeUser.username}, function(err, user){
done();
});
});
});
});
似乎沒有任何工作。我得到錯誤:2000毫秒的超時超過
其實,我得到這個錯誤的第二次運行make test:'✖1 5的測試失敗: 1)用戶#save()勾 「每個前」: 錯誤:超時超過2000毫秒' – chovy
@chovy在每個「hook *」之前它給了你方向 - '*'。因此,你有一個'beforeEach'沒有完成,可能是因爲你已經命名了接受回調的參數,但是然後不調用它,用Mocha,你必須保留它未命名(0個參數) - function(){...} - 或命名並調用它 - function(done){done ();}'。 –
我現在得到了一個不同的錯誤:https://gist.github.com/a821 7751061ad6e738b9 1)「畢竟」掛鉤: 錯誤:超過2000毫秒超時 – chovy