Skip to content

Commit

Permalink
Support spy.on with nullish prototype (#118)
Browse files Browse the repository at this point in the history
Fixes #117.

Co-authored-by: Keith Cirkel <[email protected]>
  • Loading branch information
sebamarynissen and keithamus authored Apr 6, 2023
1 parent bbdb02e commit 419cddd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion chai-spies.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
object: object
, methodName: methodName
, originalMethod: object[methodName]
, isOwnMethod: object.hasOwnProperty(methodName)
, isOwnMethod: Object.hasOwnProperty.call(object, methodName)
};
object[methodName] = method;

Expand Down
2 changes: 1 addition & 1 deletion lib/spy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions test/spies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 419cddd

Please sign in to comment.