Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yamadapc/mocha-make-stub
A simple mocha + sinon stubbing helper.
https://github.com/yamadapc/mocha-make-stub
Last synced: 2 months ago
JSON representation
A simple mocha + sinon stubbing helper.
- Host: GitHub
- URL: https://github.com/yamadapc/mocha-make-stub
- Owner: yamadapc
- License: mit
- Created: 2014-04-27T13:09:55.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-02-02T17:58:17.000Z (almost 9 years ago)
- Last Synced: 2024-10-11T22:53:31.059Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 15.6 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
mocha-make-stub
===============
[![Build Status](https://travis-ci.org/yamadapc/mocha-make-stub.png?branch=master)](https://travis-ci.org/yamadapc/mocha-make-stub)
[![Dependency Status](https://david-dm.org/yamadapc/mocha-make-stub.svg)](https://david-dm.org/yamadapc/mocha-make-stub)
[![devDependency Status](https://david-dm.org/yamadapc/mocha-make-stub/dev-status.svg)](https://david-dm.org/yamadapc/mocha-make-stub#info=devDependencies)
- - -A simple mocha + sinon stubbing helper.
Creates `before` and `after` mocha statements to stub a `method` on a `target`
before running a tests block and restore it afterwards. The stub is stored at a
`name` field in the mocha's context object (this).If no `name` is provided, the stubbed function will be stored at the context's
`method` property instead of name. This allows for a slightly smaller shorthand
for simpler cases.This is simply a syntastic sugar for using sinon with mocha. See more at:
http://sinonjs.org## Params
| Type | Name | Description |
|--------------|---------------------|------------------------------------------------------|
| **Mixed** | *[name]* | The key under which to store the sinon stub. Defaults to the `method` value |
| **Mixed** | *target* | The object to stub. If a string is provided it'll be looked up on the mocha's context |
| **Mixed** | *method* | The key of the method stub - usually a String. |
| **Function** | *[fn]* | The stub function if any. |
| **Boolean** | *[mocha_ctx=false]* | Whether to bind fn to the mocha context. |## Example
```javascript
var request = require('superagent'),
makeStub = require('mocha-make-stub'),
makeRequest = require('..'); // somethingdescribe('makeRequest(host, body, cb)', function() {
makeStub('Request$prototype$end', request.Request.prototype, 'end', function(cb) {
cb()
});it('calls Request.prototype.end', function() {
this.Request$prototype$end.called.should.be.ok;
// ...
});
});
```## `makeStub.each([name], target, method, [fn], [mocha_ctx=false])`
Like `makeStub` but uses `beforeEach` and `afterEach`.
## License
Copyright (c) 2014 Pedro Tacla Yamada. Licensed under the MIT license.
Please refer to the [LICENSE](LICENSE) file for more info.## Donations
Would you like to buy me a beer? Send bitcoin to 3JjxJydvoJjTrhLL86LGMc8cNB16pTAF3y