Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/blugavere/mock-mongoose-model
Mock mongoose model for unit testing.
https://github.com/blugavere/mock-mongoose-model
mocha mongodb mongoose testing
Last synced: 29 days ago
JSON representation
Mock mongoose model for unit testing.
- Host: GitHub
- URL: https://github.com/blugavere/mock-mongoose-model
- Owner: blugavere
- License: other
- Created: 2017-01-05T04:18:12.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-02-27T20:56:22.000Z (almost 2 years ago)
- Last Synced: 2024-11-15T00:12:08.641Z (about 2 months ago)
- Topics: mocha, mongodb, mongoose, testing
- Language: JavaScript
- Size: 130 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mock-mongoose-model
[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Dependency Status][daviddm-image]][daviddm-url]
[![Coverage percentage][coveralls-image]][coveralls-url]> Mock mongoose model to use for unit testing.
## Installation
```sh
$ npm install --save mock-mongoose-model
```## Usage
```js
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](http://benlugavere.com)
[npm-image]: https://badge.fury.io/js/mock-mongoose-model.svg
[npm-url]: https://npmjs.org/package/mock-mongoose-model
[travis-image]: https://travis-ci.org/blugavere/mock-mongoose-model.svg?branch=master
[travis-url]: https://travis-ci.org/blugavere/mock-mongoose-model
[daviddm-image]: https://david-dm.org/blugavere/mock-mongoose-model.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/blugavere/mock-mongoose-model
[coveralls-image]: https://coveralls.io/repos/blugavere/mock-mongoose-model/badge.svg
[coveralls-url]: https://coveralls.io/r/blugavere/mock-mongoose-model