Sto cercando di capire dove mettere una funzione per cancellare il database e chiudere la connessione dopo che tutti i test sono stati eseguiti.dove cancellare il database e chiudere la connessione dopo tutti i test usando la moka
Qui sono le mie prove nidificate:
//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();
});
});
});
});
Niente sembra funzionare. Ottengo l'errore: timeout di 2000 ms superato
In realtà, ottengo questo errore il 2 ° tempo di esecuzione make test: '✖ 1 su 5 test fallito: 1) #save utente() "prima di ogni" gancio: Errore: timeout 2000 ms superato ' – chovy
@chovy Ti dà la direzione - '*" prima di ogni "hook *". Quindi hai un 'beforeEach' che non sta finendo, probabilmente perché hai chiamato l'argomento per accettare una richiamata ma quindi non lo chiamano. Con Mocha, devi lasciarlo senza nome (0 argomenti) - 'function() {...}' - o chiamarlo e chiamarlo - 'function (done) {done();} '. –
Ora sto ottenendo un errore diverso: https://gist.github.com/a821 7751061ad6e738b9 1) hook "after all": Errore: timeout di 2000ms superato – chovy