Drop MongoDB database before running Mocha test
mocha.js, mongodb, mongoose, should.js, testing
Solution
solved by connect in another define.. not sure if ideal.
describe('Init', function() {
before(function (done) {
mongoose.connect('mongodb://localhost/db-test', function(){
mongoose.connection.db.dropDatabase(function(){
done()
})
})
})
describe('Database', function() {
Problem
If I try to drop the database using `after` (at the end of my tests) it works. If I try the following: ``` var db = mongoose.connect('mongodb://localhost/db-test') describe('Database', function() { before(function (done) { db.connection.db.dropDatabase(function(){ done() }) }) ... ``` it does not drop the DB. what is going on? I would prefer dropping the db before starting testing -- so that after testing I can explore the db.