Have ideas to improve npm?Join in the discussion! »

mock-mongoose-model

0.1.4 • Public • Published

mock-mongoose-model

NPM version Build Status Dependency Status Coverage percentage

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

Install

npm i mock-mongoose-model

DownloadsWeekly Downloads

58

Version

0.1.4

License

Apache-2.0

Unpacked Size

4.66 kB

Total Files

6

Last publish

Collaborators

  • avatar