mirror of
https://github.com/chaijs/chai
synced 2024-11-15 00:07:11 +00:00
Revert .empty assertion change from PR #499
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
This commit is contained in:
parent
6472cb97df
commit
8c1d8cf932
1 changed files with 10 additions and 1 deletions
|
@ -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'
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue