mercredi 1 avril 2015

How should I initialize a Mongoose connection in a Mocha unit test?

I have been looking for this all over the place. Some people seem to do



mongoose.connect('mongodb://localhost/test');


and go on with their describe calls. What about the async waiting, though?



var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function (callback) {
// yay!
});


How should I use this connection in Mocha tests? Should I put all my tests in the callback? Should I wrap the waiting-for-connection code in a unit test? Will the connection persist across describes and its?


Aucun commentaire:

Enregistrer un commentaire