Please Share on Twitter if you like #mockgoose
Mockgoose provides test database by spinning up mongod on the back when mongoose.connect call is made. By default it is using in memory store which does not have persistence.
To install the latest official version, use NPM:
npm install mockgoose --save-dev
You simply require Mongoose and Mockgoose and wrap Mongoose with Mockgoose.
var mongoose = require('mongoose');
var mockgoose = require('mockgoose');
mockgoose(mongoose).then(function() {
// mongoose connection
});
Once Mongoose has been wrapped by Mockgoose connect() will be intercepted by Mockgoose so that no MongoDB instance is created.
var Mongoose = require('mongoose').Mongoose;
var mongoose = new Mongoose();
var mockgoose = require('mockgoose');
before(function(done) {
mockgoose(mongoose).then(function() {
mongoose.connect('mongodb://example.com/TestingDB', function(err) {
done(err);
});
});
});
describe('...', function() {
it("...", function(done) {
// ...
done();
});
});
Reset method will remove ALL of the collections from a temporary store, note that this method is part of mockgoose object, and not defined under mongoose
mockgoose.reset(function() {
done()
});
Returns TRUE from mongoose object if Mockgoose is applied
if ( mongoose.isMocked === true ) {
// mongoose object is mocked
}
Method that can be applied on mongoose to remove modifications added by mockgoose, it will perform disconnect on temporary store that was created, and will not reconnect
Same as unmock, however it will reconnect to original URI that was passed during connect
This section contains instructions for developers working on the Mockgoose codebase. It is not relevant if you just want to use Mockgoose as a library in your project.
- Node.js >= 0.10.0
git clone [email protected]:mccormicka/Mockgoose.git
cd Mockgoose
npm install
npm test