Mockgoose is an in memory database mock to allow for testing of applications that rely on Mongoose.
##What is Mockgoose?
Mockgoose is a simplified in memory database that allows you to perform actions on Mongoose Models without having a running instance of MongoDB.
The main purpose of Mockgoose as you may have guessed from the name is to allow you to mock out your mongoose database during testing so that you do not have to spin up a new database for every test and teardown that same database afterwards.
##Install To install the latest official version, use NPM:
npm install mockgoose --save-dev
To run the tests and see what is supported by Mockgoose navigate to the Mockgoose folder and run the test suite
##Usage You simply require Mongoose and Mockgoose and wrap Mongoose with Mockgoose.
var mongoose = require('mongoose'); var mockgoose = require('mockgoose'); mockgoose(mongoose);
Once Mongoose has been wrapped by Mockgoose all calls to connect() and createConnection() will be intercepted by Mockgoose so that no MongoDB instance is created.
###Options mongoose required Instance of mongoose.
throwError optional Boolean true/false to throw errors on connection defaults to false.
###Connection Events Dispatches some but not all of the events supported by Mockgoose http://mongoosejs.com/docs/api.html#connection_Connection
Currently supported model operations are.
save(); create(); remove(); count(); find(); findById(); findByIdAndRemove(); findByIdAndUpdate(); findOne(); findOneAndRemove(); findOneAndUpdate(); Update();
##Validators Mockgoose includes support for validators and the unique field key.
Mockgoose comes with a reset() method that allows you to reset the Mockgoose database simply call
to delete all the collections and models in the database or call
to delete all the associated models for a schema. *schema names are case sensitive