mocha-mongo

Set of mongodb testing helpers for mocha

mocha-mongo

Set of mongodb testing helpers for mocha

mocha's TDD testing style used here and only the test function is used

var mongo = require('mocha-mongo')('mongodb://localhost');
var ready = mongo.ready(); //only need to create this once 
 
test('using the db', ready(function(dbdone) {
    
    db.collection('test').insert({hello: 'world'}, done);
}));

We need to ensure collections are cleaned before running the test.

var clean = mongo.cleanCollections(['coll1', 'coll2']); //only need to create this once 
 
test('test using cleaned collections', clean(function(dbdone) {
    
    db.collection('coll1').find().count(function(errcount) {
 
        assert.equal(count, 0);
        done();
    });
}));
var drop = mongo.drop(); //only need to create this once 
 
test('test using a fresh db', drop(function(dbdone) {
    
    db.collection('coll1').find().count(function(errcount) {
 
        assert.equal(count, 0);
        done();
    });
}));