Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Extend Sinon stubs for Mongoose methods to test chained methods easily

License

NotificationsYou must be signed in to change notification settings

Nubescope/sinon-mongoose

Repository files navigation

ExtendSinon stubs forMongoose methods to test chained methods easily

Installation

$ 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.

Usage

require('sinon')require('sinon-mongoose')

With Promises

If you are using a version < 2 ofsinon-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

With callbacks (no Promises)

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

Contributors

@jniemin
@joebowbeer
@YasharF

License

MIT ©Gonzalo Aguirre

About

Extend Sinon stubs for Mongoose methods to test chained methods easily

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp