Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow overriding asnyc stub behavior with sync behavior (#244)

  • Loading branch information...
commit 806bcda6ad7375255467817eef1a287c1219e87b 1 parent b975c9f
Tim Fischbach authored
Showing with 21 additions and 1 deletion.
  1. +10 −1 lib/sinon/stub.js
  2. +11 −0 test/sinon/stub_test.js
11 lib/sinon/stub.js
View
@@ -153,6 +153,7 @@
this.callbackArguments = [];
this.callbackContext = undefined;
this.callArgProp = undefined;
+ this.callbackAsync = false;
return this;
},
@@ -169,6 +170,7 @@
this.callbackArguments = [];
this.callbackContext = context;
this.callArgProp = undefined;
+ this.callbackAsync = false;
return this;
},
@@ -182,6 +184,7 @@
this.callbackArguments = slice.call(arguments, 1);
this.callbackContext = undefined;
this.callArgProp = undefined;
+ this.callbackAsync = false;
return this;
},
@@ -198,6 +201,7 @@
this.callbackArguments = slice.call(arguments, 2);
this.callbackContext = context;
this.callArgProp = undefined;
+ this.callbackAsync = false;
return this;
},
@@ -207,6 +211,7 @@
this.callbackArguments = slice.call(arguments, 0);
this.callbackContext = undefined;
this.callArgProp = undefined;
+ this.callbackAsync = false;
return this;
},
@@ -220,6 +225,7 @@
this.callbackArguments = slice.call(arguments, 1);
this.callbackContext = context;
this.callArgProp = undefined;
+ this.callbackAsync = false;
return this;
},
@@ -229,6 +235,7 @@
this.callbackArguments = slice.call(arguments, 1);
this.callbackContext = undefined;
this.callArgProp = prop;
+ this.callbackAsync = false;
return this;
},
@@ -242,6 +249,7 @@
this.callbackArguments = slice.call(arguments, 2);
this.callbackContext = context;
this.callArgProp = prop;
+ this.callbackAsync = false;
return this;
},
@@ -281,8 +289,9 @@
!method.match(/Async/)) {
proto[method + 'Async'] = (function (syncFnName) {
return function () {
+ var result = this[syncFnName].apply(this, arguments);
this.callbackAsync = true;
- return this[syncFnName].apply(this, arguments);
+ return result;
};
})(method);
}
11 test/sinon/stub_test.js
View
@@ -42,6 +42,17 @@ buster.testCase("sinon.stub", {
"Stub prototype should contain same amount of synchronous and asynchronous methods");
},
+ "should allow overriding async behavior with sync behavior": function() {
+ var stub = sinon.stub();
+ var callback = sinon.spy();
+
+ stub.callsArgAsync(1);
+ stub.callsArg(1);
+ stub(1, callback);
+
+ assert(callback.called);
+ },
+
"returns": {
"returns specified value": function () {
var stub = sinon.stub.create();
Please sign in to comment.
Something went wrong with that request. Please try again.