sinon-doublist
Sinon.JS test double mixins: spyMany, stubMany, stubWithReturn, stubBind
- Double multiple methods in one call.
- Use sinon.testCase-like auto-sandboxing.
- Optionally use plain objects, even empty ones, to hold method doubles.
- Select target methods
x.y.z
property path strings.
Examples
Mixin (recommended)
; ;
Mixin (manual)
;
spyMany()
Creates spies for multiple methods, even though the latter do not exist yet.
var spy = this;spy'a.b.methodA';
stubMany()
Creates a stub for method foo()
that returns false
only if called with argument 'bar'.
var obj = {};var foo = thisfoo;foo;foo;
stubWithReturn()
Creates a stub that, if called with argument 'foo', returns object containing a spy at path x.y.z
.
var obj = {}; stub = this;var spiesReturnedFromStub = obj;spiesReturnedFromStubxyz'foo';spiesReturnedFromStubxyzcalledshould;
stubBind()
{} {} var stub = thisbind;stubbind; target; // undefinedconsole; // false target; // fakeBoundTargetconsole; // true
Gotchas
useFakeTimers and setImmediate
As of 0.5.0, useFakeTimers
is no longer enabled by default. sinon
now fakes setImmediate in that feature, which may cause confusion if automatically enabled.
To enable:
thisclock = thissandbox;
Installation
component
component install codeactual/sinon-doublist
NPM
npm install sinon-doublist
Related Projects
- sinon-doublist-fs: node.js
fs
stubbing.
API
License
MIT
Tests
Node
npm test
Karma
Browser vianpm install karma
grunt build && karma start
- Browse
http://localhost:9876/karma/
jQuery 2.1.0
Custom build used in karma
test:
git clone git://github.com/jquery/jquery.git
git checkout 2.1.0
npm install
grunt custom:-sizzle,-css,-effects,-offset,-dimensions,-deprecated,-ajax/script,-ajax/jsonp,-wrap,-event-alias,-exports/amd
cp ./dist/jquery.min.js /path/to/sinon-doublist/lib/jquery.js