2.3.2 • Published 10 years ago

mocha-make-stub v2.3.2

Weekly downloads
48
License
MIT
Repository
github
Last release
10 years ago

mocha-make-stub

Build Status Dependency Status devDependency Status


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

TypeNameDescription
MixednameThe key under which to store the sinon stub. Defaults to the method value
MixedtargetThe object to stub. If a string is provided it'll be looked up on the mocha's context
MixedmethodThe key of the method stub - usually a String.
FunctionfnThe stub function if any.
Booleanmocha_ctx=falseWhether to bind fn to the mocha context.

Example

var request     = require('superagent'),
    makeStub    = require('mocha-make-stub'),
    makeRequest = require('..'); // something

describe('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 file for more info.

2.3.2

10 years ago

2.3.1

10 years ago

2.3.0

10 years ago

2.2.0

10 years ago

2.1.0

11 years ago

2.0.1

11 years ago

2.0.0

11 years ago

1.0.1

11 years ago

1.0.0

11 years ago