All Projects → underscopeio → sinon-mongoose

underscopeio / sinon-mongoose

Licence: MIT license
Extend Sinon stubs for Mongoose methods to test chained methods easily

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to sinon-mongoose

ts-mock-imports
Intuitive mocking library for Typescript class imports
Stars: ✭ 103 (+18.39%)
Mutual labels:  mock, stub, sinon
Cuckoo
Boilerplate-free mocking framework for Swift!
Stars: ✭ 1,344 (+1444.83%)
Mutual labels:  mock, stub
Timex
A test-friendly replacement for golang's time package
Stars: ✭ 53 (-39.08%)
Mutual labels:  mock, stub
Mimic
A mocking library for Elixir
Stars: ✭ 104 (+19.54%)
Mutual labels:  mock, stub
Dyson
Node server for dynamic, fake JSON.
Stars: ✭ 814 (+835.63%)
Mutual labels:  mock, stub
Wiremockui
Wiremock UI - Tool for creating mock servers, proxies servers and proxies servers with the option to save the data traffic from an existing API or Site.
Stars: ✭ 38 (-56.32%)
Mutual labels:  mock, stub
Mongodb Memory Server
Spinning up mongod in memory for fast tests. If you run tests in parallel this lib helps to spin up dedicated mongodb servers for every test file in MacOS, *nix, Windows or CI environments (in most cases with zero-config).
Stars: ✭ 1,376 (+1481.61%)
Mutual labels:  mock, mongoose
phake
PHP Mocking Framework
Stars: ✭ 464 (+433.33%)
Mutual labels:  mock, stub
Mockit
A tool to quickly mock out end points, setup delays and more...
Stars: ✭ 1,534 (+1663.22%)
Mutual labels:  mock, stub
Spy
Clojure/ClojureScript library for stubs, spies and mocks.
Stars: ✭ 131 (+50.57%)
Mutual labels:  mock, stub
Mockingbird
Simplify software testing, by easily mocking any system using HTTP/HTTPS, allowing a team to test and develop against a service that is not complete or is unstable or just to reproduce planned/edge cases.
Stars: ✭ 149 (+71.26%)
Mutual labels:  mock, stub
Ohhttpstubs
Stub your network requests easily! Test your apps with fake network data and custom response time, response code and headers!
Stars: ✭ 4,831 (+5452.87%)
Mutual labels:  mock, stub
Swiftmockgeneratorforxcode
An Xcode extension (plugin) to generate Swift test doubles automatically.
Stars: ✭ 522 (+500%)
Mutual labels:  mock, stub
Mocha
Mocha is a mocking and stubbing library for Ruby
Stars: ✭ 1,065 (+1124.14%)
Mutual labels:  mock, stub
Hippolyte
HTTP Stubbing in Swift
Stars: ✭ 109 (+25.29%)
Mutual labels:  mock, stub
Impersonator
Ruby library to record and replay object interactions
Stars: ✭ 100 (+14.94%)
Mutual labels:  mock, stub
stub-server
Stub server for REST APIs
Stars: ✭ 14 (-83.91%)
Mutual labels:  mock, stub
DeepfakeHTTP
DeepfakeHTTP is a web server that uses HTTP dumps as a source for responses.
Stars: ✭ 373 (+328.74%)
Mutual labels:  mock, stub
Mockery
Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL).
Stars: ✭ 10,048 (+11449.43%)
Mutual labels:  mock, stub
mocka
Mocka - The complete testing framework for LUA and Nginx
Stars: ✭ 26 (-70.11%)
Mutual labels:  mock, stub

sinon-mongoose NPM version Build Status devDependency Status Coverage percentage

Extend Sinon stubs for Mongoose methods to test chained methods easily

Installation

$ npm install sinon-mongoose

IMPORTANT! As of version 2.2.0 we are supporting sinon >= 5. If you are using sinon < 5 you could have some problems due to some breaking changes in sinon 5.

Usage

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

With Promises

If you are using a version < 2 of sinon-mongoose we recommend you to use sinon-as-promised to have resolves and rejects methods on stubs.

If you want to test this

MongooseModel.find()
  .limit(10)
  .sort('-date')
  .exec()
  .then(function(result) {
    console.log(result)
  })

Just mock and expects as usual and use chain to expects the chained methods. Finally call resolves or rejects (remember to require sinon-as-promised).

sinon
  .mock(MongooseModel)
  .expects('find')
  .chain('limit')
  .withArgs(10)
  .chain('sort')
  .withArgs('-date')
  .chain('exec')
  .resolves('SOME_VALUE')

See complete example

With callbacks (no Promises)

If you want to test this

MongooseModel.find()
  .limit(10)
  .sort('-date')
  .exec(function(err, result) {
    console.log(result)
  })

Just mock and expects as usually and use chain to expects the chained methods. Finally yields as always.

sinon
  .mock(MongooseModel)
  .expects('find')
  .chain('limit')
  .withArgs(10)
  .chain('sort')
  .withArgs('-date')
  .chain('exec')
  .yields(null, 'SOME_VALUE')

See complete example

Contributors

@jniemin
@joebowbeer
@YasharF

License

MIT © Gonzalo Aguirre

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].