Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,14 @@
/**
* Assert property "length" exists and has value of _n_.
*
* @param {Number} n
* @param {Number|undefined} n
* @api public
*/

Assertion.prototype.length = function (n) {
expect(this.obj).to.have.property('length');
var len = this.obj.length;
n = n === undefined ? 0 : n;
this.assert(
n == len
, function(){ return 'expected ' + i(this.obj) + ' to have a length of ' + n + ' but got ' + len }
Expand Down
14 changes: 14 additions & 0 deletions test/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,20 @@ describe('expect', function () {
}, "expected 'asd' to not have a length of 3");
});

it('should test length without input', function () {
expect('test').to.have.length();
expect('test').to.not.have.length();
expect([1,2,3]).to.have.length();

err(function () {
expect(4).to.have.length();
}, 'expected 4 to have a property \'length\'');

err(function () {
expect('asd').to.not.have.length();
}, "expected 'asd' to not have a length of 3");
});

it('should test eql(val)', function () {
expect('test').to.eql('test');
expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
Expand Down