Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop MongoDB database before running Mocha test

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.

like image 470
fusio Avatar asked Aug 20 '13 12:08

fusio


1 Answers

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() {
like image 62
fusio Avatar answered Sep 30 '22 23:09

fusio