MONGODB-MOCKER
The package mongodb-mocker is a class that abstracts an in-memory mongodb database. Its purpose is to aid developing of tests that use the mongodb database without writing a mock or connecting to a real database.
Installation
npm install --save-dev mongodb-mocker
Basic Usage
const MongodbMocker = ;const yourDatabase = ;const mongodbMocker = port: '8000' ; ;
Using with Mongoose
in Names.js
const mongoose = ; const schema = name: type: String max: 50 'Name too long (>50)' min: 1 required: true ; const Names = mongoose; moduleexports = Names;
in db.js
const mongoose = ; { thismongoose = mongoose; thismockedServer = null; } { return thismongoose; } { const url = processenvMONGODB_URL; thisuri = `mongodb:///`; return Promise ; } moduleexports = Db;
in db.spec.js
/* global describe it before beforeEach afterEach */processenvNODE_ENV = 'test';processenvMONGODB_URL = 'localhost:8000'; const chai = ;const Db = ;const Names = ;const MongodbMocker = ; const should = chai;const db = ; ;
Run this example from the root of this repository
npm imocha ./example/db.spec.js