Set of mongodb testing helpers for mocha
JavaScript
Switch branches/tags
Latest commit f129b36 Mar 2, 2017 @arunoda Update mongodb driver.
Permalink
Failed to load latest commit information.
test fixed typo in test Apr 18, 2013
.travis.yml added mongodb service Apr 18, 2013
README.md Update README.md Jan 3, 2014
index.js initial version Apr 18, 2013
package.json Update mongodb driver. Mar 2, 2017

README.md

mocha-mongo Build Status

Set of mongodb testing helpers for mocha

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

Initialization

var mongo = require('mocha-mongo')('mongodb://localhost');

Using the db in tests

var ready = mongo.ready(); //only need to create this once

test('using the db', ready(function(db, done) {
	
	db.collection('test').insert({hello: 'world'}, done);
}));

Use fresh collections without data

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(db, done) {
	
	db.collection('coll1').find().count(function(err, count) {

		assert.equal(count, 0);
		done();
	});
}));

Drop the whole db

var drop = mongo.drop(); //only need to create this once

test('test using a fresh db', drop(function(db, done) {
	
	db.collection('coll1').find().count(function(err, count) {

		assert.equal(count, 0);
		done();
	});
}));