chainsinon

0.1.1 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i chainsinon

Weekly Downloads

1

Version

0.1.1

License

ISC

Last publish

Collaborators

  • dsummersl