New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@cantremember/mockgoose

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cantremember/mockgoose

Mockgoose is an in memory database mock to allow for testing of applications that rely on Mongoose.

5.3.0-eta
latest
Source
npm
Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

Please Share on Twitter if you like #mockgoose

What is Mockgoose?

Mockgoose provides test database by spinning up mongod on the back when mockgoose.connect call is made. By default it is using in memory store which does not have persistence.

Install

To install the latest official version, use NPM:

npm install mockgoose --save-dev

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 connect() will be intercepted by Mockgoose so that no MongoDB instance is created.

Mocha

var Mongoose = require('mongoose').Mongoose;
var mongoose = new Mongoose();

var mockgoose = require('mockgoose');
mockgoose(mongoose);

before(function(done) {
    mongoose.connect('mongodb://example.com/TestingDB', function(err) {
        done(err);
    });
});

describe('...', function() {
	it("...", function(done) {
		// ...
        done();
    });
});

Helper methods and variables

reset(callback)

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()
});

isMocked

Returns TRUE from mongoose object if Mockgoose is applied

if ( mongoose.isMocked === true ) {
  // mongoose object is mocked
}

unmock(callback)

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

unmockAndReconnect(callback)

Same as unmock, however it will reconnect to original URI that was passed during connect

Development

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.

Pre-requisites

  • Node.js >= 0.10.0
  • Grunt (npm install -g grunt-cli)

Setup

git clone git@github.com:mccormicka/Mockgoose.git
cd Mockgoose
npm install
grunt test

Keywords

mongodb

FAQs

Package last updated on 14 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts