Browse files

Add `assert.lengthOf` on objects

Fixes #139.
  • Loading branch information...
1 parent 38817c1 commit 03f60dd564188f84bf518487db27e478ce45308b @Filirom1 Filirom1 committed with mmalecki Apr 21, 2012
Showing with 3 additions and 1 deletion.
  1. +2 −1 lib/assert/macros.js
  2. +1 −0 test/assert-test.js
View
3 lib/assert/macros.js
@@ -111,7 +111,8 @@ assert.isNotEmpty = function (actual, message) {
};
assert.lengthOf = function (actual, expected, message) {
- if (actual.length !== expected) {
+ var len = isObject(actual) ? Object.keys(actual).length : actual.length;
+ if (len !== expected) {
assert.fail(actual, expected, message || "expected {actual} to have {expected} element(s)", "length", assert.length);
}
};
View
1 test/assert-test.js
@@ -13,6 +13,7 @@ vows.describe('vows/assert').addBatch({
"`lengthOf`": function () {
assert.lengthOf("hello world", 11);
assert.lengthOf([1, 2, 3], 3);
+ assert.lengthOf({goo: true, gies: false}, 2);
},
"`isDefined`": function () {
assert.isDefined(null);

0 comments on commit 03f60dd

Please sign in to comment.