- Notifications
You must be signed in to change notification settings - Fork28
Extend Sinon stubs for Mongoose methods to test chained methods easily
License
Nubescope/sinon-mongoose
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
ExtendSinon stubs forMongoose methods to test chained methods easily
$ npm install sinon-mongoose
IMPORTANT! As of version2.2.0 we are supporting sinon >= 5.If you are using sinon < 5 you could have some problems due to somebreaking changes in sinon 5.
require('sinon')require('sinon-mongoose')
If you are using a version < 2 of
sinon-mongoose
we recommend you to usesinon-as-promised to haveresolves
andrejects
methods on stubs.
If you want to test this
MongooseModel.find().limit(10).sort('-date').exec().then(function(result){console.log(result)})
Justmock
andexpects
as usual and usechain
to expects the chained methods.Finally callresolves
orrejects
(remember to requiresinon-as-promised).
sinon.mock(MongooseModel).expects('find').chain('limit').withArgs(10).chain('sort').withArgs('-date').chain('exec').resolves('SOME_VALUE')
See completeexample
If you want to test this
MongooseModel.find().limit(10).sort('-date').exec(function(err,result){console.log(result)})
Justmock
andexpects
as usually and usechain
to expects the chained methods.Finallyyields
as always.
sinon.mock(MongooseModel).expects('find').chain('limit').withArgs(10).chain('sort').withArgs('-date').chain('exec').yields(null,'SOME_VALUE')
See completeexample
MIT ©Gonzalo Aguirre
About
Extend Sinon stubs for Mongoose methods to test chained methods easily
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.