npm.io
0.1.1 • Published 12 years ago

chainsinon

Licence
ISC
Version
0.1.1
Deps
1
Vulns
0
Weekly
0
Stars
1

chainsinon

A Sinon utility function to return complex stubbed objects.

Install

Use npm:

npm install --save-dev chainsinon

Usage

The chainsinon function stubs an arbitrary list of functions on an object. For example:

var chainsinon = require("chainsinon");

var mockObject = chainsinon("mainMethod.subFunction.subSubFunction");

// One can then call any of the functions mentioned:
mockObject.mainMethod();
mockObject.mainMethod().subFunction().subSubFunction();

// Each mocked method is a sinon stub. You can apply custom behavior or
// verifications on the objects as per usual...
mockObject["mainMethod.subFunction.subSubFunction"].returns(4);

// so this now returns 4:
mockObject.mainMethod().subFunction().subSubFunction();

// call counts are of course respected:
mockObject["mainMethod"].called;    // == true
mockObject["mainMethod"].callCount; // == 3 (three times so far)

See test cases for more examples.

Keywords