Updated code based on discussion

This commit is contained in:
Dai 2015-06-30 17:14:46 +01:00 committed by Grant Snodgrass
parent e0ee3def23
commit 128c1126ac
2 changed files with 9 additions and 22 deletions

View file

@ -507,19 +507,10 @@ module.exports = function (chai, _) {
*/
Assertion.addProperty('empty', function () {
var obj = flag(this, 'object')
, expected = obj;
if (obj == null) {
expected = flag(this, 'negate');
} else if (Array.isArray(obj) || 'string' === typeof obj) {
expected = obj.length === 0;
} else if ('object' === typeof obj) {
expected = Object.keys(obj).length === 0;
}
var obj = flag(this, 'object');
new Assertion(obj).to.exist;
this.assert(
expected
Object.keys(Object(obj)).length === 0
, 'expected #{this} to be empty'
, 'expected #{this} not to be empty'
);

View file

@ -472,33 +472,29 @@ describe('expect', function () {
expect({foo: 'bar'}).to.be.empty;
}, "expected { foo: \'bar\' } to be empty");
err(function(){
expect(0).to.be.empty;
}, "expected 0 to be empty");
err(function(){
expect(null).to.be.empty;
}, "expected null to be empty");
}, "expected null to exist");
err(function(){
expect(undefined).to.be.empty;
}, "expected undefined to be empty");
}, "expected undefined to exist");
err(function(){
expect().to.be.empty;
}, "expected undefined to be empty");
}, "expected undefined to exist");
err(function(){
expect(null).to.not.be.empty;
}, "expected null not to be empty");
}, "expected null to exist");
err(function(){
expect(undefined).to.not.be.empty;
}, "expected undefined not to be empty");
}, "expected undefined to exist");
err(function(){
expect().to.not.be.empty;
}, "expected undefined not to be empty");
}, "expected undefined to exist");
});