diff --git a/lib/chai/core/assertions.js b/lib/chai/core/assertions.js index 158a6801..b5e2dbcd 100644 --- a/lib/chai/core/assertions.js +++ b/lib/chai/core/assertions.js @@ -2524,7 +2524,7 @@ function assertKeys(keys) { }); } - if (!keys.length) { + if (!keys.length && actual.length) { throw new AssertionError(flagMsg + 'keys required', undefined, ssfi); } diff --git a/test/expect.js b/test/expect.js index ed74a90f..47eae762 100644 --- a/test/expect.js +++ b/test/expect.js @@ -3019,6 +3019,13 @@ describe('expect', function () { }); + it('should accept empty keys when the object is empty', function () { + expect({}).to.have.keys(); + expect({}).to.have.keys([]); + expect({}).to.contain.keys(); + expect({}).to.contain.keys([]); + }); + it('keys(array) will not mutate array (#359)', function () { var expected = [ 'b', 'a' ]; var original_order = [ 'b', 'a' ];