Skip to content

Commit

Permalink
Revert .empty assertion change from PR #499
Browse files Browse the repository at this point in the history
The change introduced in #499 breaks compatibility with Array-like
objects (e.g. mongoose arrays).
It should be applied in the next major version.

Fix #537
  • Loading branch information
tusbar committed Oct 21, 2015
1 parent 6472cb9 commit 8c1d8cf
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,17 @@ module.exports = function (chai, _) {
*/

Assertion.addProperty('empty', function () {
var obj = flag(this, 'object')
, expected = obj;

if (Array.isArray(obj) || 'string' === typeof object) {
expected = obj.length;
} else if (typeof obj === 'object') {
expected = Object.keys(obj).length;
}

this.assert(
Object.keys(Object(flag(this, 'object'))).length === 0
!expected
, 'expected #{this} to be empty'
, 'expected #{this} not to be empty'
);
Expand Down

0 comments on commit 8c1d8cf

Please sign in to comment.