mock-mongoose-model
v0.1.4
Published
Mock mongoose model to use for unit testing.
Downloads
414
Readme
mock-mongoose-model
Mock mongoose model to use for unit testing.
Installation
$ npm install --save mock-mongoose-model
Usage
const assert = require('assert');
const sinon = require('sinon');
const MockMongooseModel = require('mock-mongoose-model');
// stub the mock
sinon.stub(MockMongooseModel, 'findOne').yields(null, { name: 'whiskers' });
// use it somewhere
MockMongooseModel.findOne({ name: 'whiskers' }, (err, doc) => {
assert(doc.name === 'whiskers');
});
// supports method chaining
sinon.stub(MockMongooseModel, 'exec').yields(null, { name: 'rex' });
MockMongooseModel.findById('1').select('name').exec((err, doc) => {
assert(doc.name === 'rex')
});
// for multiple mongoose models, use Object.assign({}, MockMongooseModel);
License
Apache-2.0 © blugavere