simple-mock
Advanced tools
Comparing version 0.2.4 to 0.2.5
@@ -5,2 +5,3 @@ (function (global, module) { // Browser compatibility | ||
var mocks = []; | ||
var totalCalls = 0; | ||
@@ -78,2 +79,3 @@ /** | ||
var call = { | ||
k: totalCalls++, // Keep count of calls to record the absolute order of calls | ||
args: Array.prototype.slice.call(arguments, 0) | ||
@@ -80,0 +82,0 @@ }; |
{ | ||
"name": "simple-mock", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "Super simple mocks, stubs, and spies with 1-step sandbox restore", | ||
@@ -15,3 +15,2 @@ "main": "index.js", | ||
"test", | ||
"sinon", | ||
"simplemock", | ||
@@ -18,0 +17,0 @@ "simple", |
@@ -119,2 +119,3 @@ # simple-mock ![Project status](https://secure.travis-ci.org/jupiter/node-simple-mock.png?branch=master) | ||
- **call.threw** the error thrown by the wrapped function | ||
- **call.k** autoincrementing number, can be compared to evaluate call order | ||
@@ -129,3 +130,3 @@ ### spy.lastCall | ||
Configures this stub to call back with the arguments passed. It will use the last argument as callback, or argument at `argumentIndex`. Subsequent calls of this on the same stub (chainable) will queue up different behaviours for each subsequent call of the stub. | ||
Configures this stub to call back with the arguments passed. It will use either the last argument as callback, or the argument at `argumentIndex`. Subsequent calls of this on the same stub (chainable) will queue up different behaviours for each subsequent call of the stub. | ||
@@ -154,2 +155,2 @@ ### stub.returnWith(val) | ||
The most complete, framework-agnostic mocking library is [sinon.js](http://sinonjs.org/). It also has pages of documentation and lots of sugar-coating that we generally don't need. Just because it is there doesn't mean you need to use it. Keep it simple! | ||
The most complete, framework-agnostic mocking library is [sinon.js](http://sinonjs.org/). It also has pages of documentation and lots of sugar-coating that we generally don't need. Just because it is there doesn't mean you need it. Keep it simple! |
18
test.js
@@ -162,2 +162,20 @@ 'use strict'; | ||
}); | ||
describe('calls of multiple spies', function() { | ||
it('can be compared to determine the order they were called in', function() { | ||
var spy1 = simple.spy(function(){}); | ||
var spy2 = simple.spy(function(){}); | ||
var spy3 = simple.spy(function(){}); | ||
spy1(); | ||
spy3(); | ||
spy2(); | ||
spy1(); | ||
assert(spy1.lastCall.k > spy2.lastCall.k); | ||
assert(spy1.lastCall.k > spy3.lastCall.k); | ||
assert(spy2.lastCall.k > spy3.lastCall.k); | ||
assert(spy3.lastCall.k > spy1.calls[0].k); | ||
}); | ||
}); | ||
}); | ||
@@ -164,0 +182,0 @@ |
28019
667
154