Skip to content
Browse files

Re-added feature with a test to go with it

When a user calls setReturnValue with multiple values, then calls it
again, it'll reset the call count so that it starts cycling from the
beginning again
  • Loading branch information...
1 parent d4a87d7 commit e7ab3c358c062e20821fbe6e535876258bc3b7b7 @nathanmacinnes committed Jan 18, 2012
Showing with 11 additions and 1 deletion.
  1. +4 −1 lib/pretendr.js
  2. +7 −0 test/tests.js
View
5 lib/pretendr.js
@@ -13,7 +13,7 @@ PRETENDR.mock = function (obj, proto) {
// Give functions the required return value setting and expectations
mockAFunction = function (original) {
- var callCount = 0,
+ var callCount,
mockFn,
returnValues = [],
returnFunction;
@@ -33,6 +33,9 @@ PRETENDR.mock = function (obj, proto) {
return ret;
};
mockFn.setReturnValue = function () {
+ // set to 0 so that it doesn't continue cycling through from where
+ // it left off which would confuse the user
+ callCount = 0;
returnValues = arguments;
};
mockFn.setFunction = function (fn) {
View
7 test/tests.js
@@ -85,6 +85,13 @@
equal(this.mockObj(), 'val1');
equal(this.mockObj(), 2);
});
+ test("when setting then changing multiple return values, will start from" +
+ "the beginning", function () {
+ this.mockObj.setReturnValue('val1', 2, 'value 3');
+ this.mockObj();
+ this.mockObj.setReturnValue(1, 'value 2', 'val3');
+ equal(this.mockObj(), 1);
+ });
test("allows creating a function to define return values", function () {
var args;
this.mockObj.setFunction(function () {

0 comments on commit e7ab3c3

Please sign in to comment.
Something went wrong with that request. Please try again.