Skip to content

riox/Mockgoose

 
 

Repository files navigation

Build Status

Please Share on Twitter if you like #mockgoose

##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

npm test

##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

Supported Events

connecting
connected
open
error

Currently supported model operations are.

save();
create();
remove();
count();
find();
findById();
findByIdAndRemove();
findByIdAndUpdate();
findOne();
findOneAndRemove();
findOneAndUpdate();
Update();

##Operators

##Options

  • multi : 0/1 defaults to 0
  • upsert : true/false defaults to false
  • sort : one level of sorting for find operations {sort: {name:1}}
  • skip
  • limit

##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

mockgoose.reset() 

to delete all the collections and models in the database or call

mockgoose.reset('schema name')*

to delete all the associated models for a schema. *schema names are case sensitive

About

Mocking for Mongoose

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%