diff --git a/chai-spies.js b/chai-spies.js index 2e48cca..f58bdfb 100644 --- a/chai-spies.js +++ b/chai-spies.js @@ -87,7 +87,7 @@ object: object , methodName: methodName , originalMethod: object[methodName] - , isOwnMethod: object.hasOwnProperty(methodName) + , isOwnMethod: Object.hasOwnProperty.call(object, methodName) }; object[methodName] = method; diff --git a/lib/spy.js b/lib/spy.js index 97285c9..b3eb0e6 100644 --- a/lib/spy.js +++ b/lib/spy.js @@ -81,7 +81,7 @@ module.exports = function (chai, _) { object: object , methodName: methodName , originalMethod: object[methodName] - , isOwnMethod: object.hasOwnProperty(methodName) + , isOwnMethod: Object.hasOwnProperty.call(object, methodName) }; object[methodName] = method; diff --git a/test/spies.js b/test/spies.js index 7ec93da..ab4acf8 100644 --- a/test/spies.js +++ b/test/spies.js @@ -609,6 +609,16 @@ describe('Chai Spies', function () { object.push().should.equal(5); object.pop().should.equal(5); }) + + it('should work with a nullish prototype', function() { + var nullish = Object.create(null); + nullish.method = function() { + return 1; + }; + chai.spy.on(nullish, 'method'); + nullish.method().should.equal(1); + }); + }); describe('spy interface', function () {