Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ownProperty on objects with no prototype #689

Merged
merged 1 commit into from
Apr 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/chai/core/assertions.js
Expand Up @@ -937,7 +937,7 @@ module.exports = function (chai, _) {
if (msg) flag(this, 'message', msg);
var obj = flag(this, 'object');
this.assert(
obj.hasOwnProperty(name)
Object.prototype.hasOwnProperty.call(obj, name)
, 'expected #{this} to have own property ' + _.inspect(name)
, 'expected #{this} to not have own property ' + _.inspect(name)
);
Expand Down
4 changes: 4 additions & 0 deletions test/expect.js
Expand Up @@ -565,6 +565,10 @@ describe('expect', function () {
expect('test').to.haveOwnProperty('length');
expect({ length: 12 }).to.have.ownProperty('length');

var objNoProto = Object.create(null);
objNoProto.a = 'a';
expect(objNoProto).to.have.ownProperty('a');

err(function(){
expect({ length: 12 }).to.not.have.ownProperty('length', 'blah');
}, "blah: expected { length: 12 } to not have own property 'length'");
Expand Down
4 changes: 4 additions & 0 deletions test/should.js
Expand Up @@ -417,6 +417,10 @@ describe('should', function() {
({ length: 12 }).should.have.ownProperty('length');
({ 1: 1 }).should.have.ownProperty(1);

var objNoHasOwnProperty = {hasOwnProperty: null};
objNoHasOwnProperty.a = 'a';
objNoHasOwnProperty.should.have.ownProperty('a');

err(function(){
({ length: 12 }).should.not.have.ownProperty('length', 'blah');
}, "blah: expected { length: 12 } to not have own property 'length'");
Expand Down