0.1.4 • Published 5 years ago

mock-mongoose-model v0.1.4

Weekly downloads
47
License
Apache-2.0
Repository
github
Last release
5 years ago

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

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

6 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago