Permalink
Browse files

add a reset method to wrapped functions

  • Loading branch information...
1 parent 352a36e commit efbad6cf9edd03410fb09c8f39937397e8a9c9ef @vilmibm committed Sep 7, 2012
Showing with 19 additions and 7 deletions.
  1. +2 −5 README.md
  2. +6 −0 lib/akeley.js
  3. +1 −1 package.json
  4. +10 −1 tests/test.js
View
@@ -2,11 +2,6 @@
_being a mocking utility_
-## status
-
-very much a work in progress. not recommended for any use outside of
-experimentation until further notice.
-
## mock something out
var Mock = require('akeley').Mock
@@ -40,6 +35,8 @@ experimentation until further notice.
mock_akeley.think.calls; // 2
mock_akeley.think.args; // [ ['i hate the mi-go'], ['i love the mi-go'] ]
+ mock_akeley.think.reset(); // reset called, calls, args
+
## just make a watched function
// set a return value
View
@@ -44,6 +44,12 @@ Mock.create_func = function(opts) {
else { return return_value }
};
+ wrapped.reset = function() {
+ function_spy.called = false;
+ function_spy.calls = 0;
+ function_spy.args = [];
+ };
+
['calls', 'args', 'called'].forEach(function(k) {
Object.defineProperty(wrapped, k, {
get: function() { return function_spy[k]; }
View
@@ -1,6 +1,6 @@
{
"name": "akeley",
- "version": "0.3.2",
+ "version": "0.4.0",
"author": "nathaniel k smith <nathanielksmith@gmail.com>",
"description": "a mocking utility library",
"main": "./lib/akeley",
View
@@ -29,7 +29,6 @@ exports.test_object_spec = {
test.equal(mock_cat.vitals.appearance.legs, 4, 'legs set');
test.deepEqual(mock_cat.vitals.appearance.colours, ['orange', 'black', 'brown'], 'colours set');
test.done()
-
},
test_functions: function(test) {
var cat = {
@@ -140,6 +139,16 @@ exports.test_mock_function = {
mock_f();
test.ok(mock_f.called, 'saw it was called');
+ test.done();
+ },
+ test_reset: function(test) {
+ var mock_f = Mock.create_func();
+ mock_f(); mock_f(); mock_f();
+ test.equal(mock_f.calls, 3, 'sanity: saw three calls');
+ mock_f.reset();
+ test.equal(mock_f.calls, 0, 'reset call count');
+ test.equal(mock_f.called, false, 'reset called boolean');
+ test.deepEqual(mock_f.args, [], 'reset args');
test.done();
}
};

0 comments on commit efbad6c

Please sign in to comment.