diff --git a/lib/chai/core/assertions.js b/lib/chai/core/assertions.js index 71baf3a99..1ea9e4c0d 100644 --- a/lib/chai/core/assertions.js +++ b/lib/chai/core/assertions.js @@ -2386,7 +2386,7 @@ module.exports = function (chai, _) { }); } - if (!keys.length) { + if (!keys.length && actual.length) { throw new AssertionError(flagMsg + 'keys required', undefined, ssfi); } diff --git a/test/assert.js b/test/assert.js index 1842f3686..0e1ddc012 100644 --- a/test/assert.js +++ b/test/assert.js @@ -994,6 +994,9 @@ describe('assert', function () { assert.hasAllKeys({ foo: 1, bar: 2 }, [ 'foo', 'bar' ]); assert.hasAllKeys({ foo: 1 }, { foo: 30 }); assert.hasAllKeys({ foo: 1, bar: 2 }, { 'foo': 6, 'bar': 7 }); + assert.hasAllKeys({}); + assert.hasAllKeys({}, []); + assert.hasAllKeys({}, {}); assert.containsAllKeys({ foo: 1, bar: 2, baz: 3 }, [ 'foo', 'bar' ]); assert.containsAllKeys({ foo: 1, bar: 2, baz: 3 }, [ 'bar', 'foo' ]); @@ -1004,6 +1007,9 @@ describe('assert', function () { assert.containsAllKeys({ foo: 1, bar: 2 }, { 'bar': 7 }); assert.containsAllKeys({ foo: 1, bar: 2 }, { 'foo': 6 }); assert.containsAllKeys({ foo: 1, bar: 2 }, { 'bar': 7, 'foo': 6 }); + assert.containsAllKeys({}); + assert.containsAllKeys({}, []); + assert.containsAllKeys({}, {}); assert.doesNotHaveAllKeys({ foo: 1, bar: 2 }, [ 'baz' ]); assert.doesNotHaveAllKeys({ foo: 1, bar: 2 }, [ 'foo' ]); @@ -1028,6 +1034,10 @@ describe('assert', function () { assert.doesNotHaveAnyKeys({ foo: 1, bar: 2 }, { baz: 1, biz: 2, fake: 3 }); assert.doesNotHaveAnyKeys({ foo: 1, bar: 2 }, { baz: 1 }); + assert.doesNotHaveAnyKeys({}); + assert.doesNotHaveAnyKeys({}, []); + assert.doesNotHaveAnyKeys({}, {}); + var enumProp1 = 'enumProp1' , enumProp2 = 'enumProp2' , nonEnumProp = 'nonEnumProp' diff --git a/test/expect.js b/test/expect.js index 78ab661bf..e9d89b49d 100644 --- a/test/expect.js +++ b/test/expect.js @@ -2566,6 +2566,17 @@ describe('expect', function () { expect({ foo: 1, bar: 2 }).not.have.all.keys({ 'baz': 8, 'foo': 7 }); expect({ foo: 1, bar: 2 }).not.contain.all.keys({ 'baz': 8, 'foo': 7 }); + expect({}).to.have.all.keys(); + expect({}).to.have.all.keys({}); + expect({}).to.have.all.keys([]); + expect({}).contain.keys(); + expect({}).contain.keys({}); + expect({}).contain.keys([]); + + expect({}).to.not.have.any.keys(); + expect({}).not.have.any.keys({}); + expect({}).not.any.keys([]); + var enumProp1 = 'enumProp1' , enumProp2 = 'enumProp2' , nonEnumProp = 'nonEnumProp' diff --git a/test/should.js b/test/should.js index 4e97f4213..94300db8a 100644 --- a/test/should.js +++ b/test/should.js @@ -2165,6 +2165,17 @@ describe('should', function() { ({ 1: 1, 2: 2 }).should.have.any.keys(1, 3); ({ 1: 1, 2: 2 }).should.contain.keys(1); + ({}).should.have.all.keys(); + ({}).should.have.all.keys([]); + ({}).should.have.all.keys({}); + ({}).should.contain.keys(); + ({}).should.contain.keys([]); + ({}).should.contain.keys({}); + + ({}).should.not.have.any.keys(); + ({}).should.not.have.any.keys([]); + ({}).should.not.have.any.keys({}); + var enumProp1 = 'enumProp1' , enumProp2 = 'enumProp2' , nonEnumProp = 'nonEnumProp'