Skip to content

Commit

Permalink
Merge pull request #54 from felixge/stub-prototype-properties
Browse files Browse the repository at this point in the history
Make stub work for prototype methods
  • Loading branch information
cjohansen committed Nov 21, 2011
2 parents 86a2f72 + f28a2aa commit cd7f8bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/sinon/stub.js
Expand Up @@ -44,7 +44,7 @@

if (!property && !!object && typeof object == "object") {
for (var prop in object) {
if (object.hasOwnProperty(prop) && typeof object[prop] == "function") {
if (typeof object[prop] === "function") {
stub(object, prop);
}
}
Expand Down
23 changes: 14 additions & 9 deletions test/sinon/stub_test.js
Expand Up @@ -385,22 +385,27 @@ if (typeof require == "function" && typeof testCase == "undefined") {
assertFunction(obj.func3.restore);
},

"should stub prototype methods": function () {
function Obj() {};
Obj.prototype.func1 = function() {};
var obj = new Obj();

var stub = sinon.stub(obj);

assertFunction(obj.func1.restore);
},

"should return object": function () {
var object = {};

assertSame(object, sinon.stub(object));
},

"should not stub inherited methods": function () {
var getName = function () {};
var person = { getName: getName };
var dude = sinon.create(person);

sinon.stub(dude);
"should only stub functions": function () {
var object = {foo: 'bar'};
sinon.stub(object);

assertUndefined(dude.toString.restore);
assertUndefined(dude.valueOf.restore);
assertSame(getName, dude.getName);
assertEquals('bar', object.foo);
}
});

Expand Down

0 comments on commit cd7f8bb

Please sign in to comment.