Mongo Mocker
A promise/generator driven Mongo mocking layer, with in memory state and mongo operator support.
Install
npm i mongo-mocker --save-dev
Requirements
Node: 6+
Setup
MongoMocker([mockModulePath], initialCollections)
const MongoMocker = ;const mongo = ; /** <==≠ OR ≠===========================> **/ const mongo = 'module/path/for/mongo/driver' {}; /** <==≠ OR (just the mongoDB) ≠========> **/ const mongo = ;
In src code all normal operations happen and work as expected
mongo;// { _id: 'xxxx3', name: 'Dean' }
Helpers
const mongo = ; mongomock;// Returns internal state of users collects: [{ _id: '1', name: 'Sam' }] mongomockclear'test';// Clear a specific collection mongomock;// Clears all collections
In Tests
const MongoMocker = ; ;