Skip to content

Commit

Permalink
Add assert.lengthOf on objects
Browse files Browse the repository at this point in the history
Fixes #139.
  • Loading branch information
Filirom1 authored and mmalecki committed Jun 17, 2012
1 parent 38817c1 commit 03f60dd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/assert/macros.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand Down
1 change: 1 addition & 0 deletions test/assert-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 03f60dd

Please sign in to comment.