Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hapijs/code
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Nov 3, 2017
2 parents d2af62a + 7cf8a2d commit bece7c3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.js
Expand Up @@ -259,7 +259,7 @@ internals.addMethod('empty', internals.empty);

internals.length = function (size) {

internals.assert(this, typeof this._ref === 'object' || typeof this._ref === 'string', 'Can only assert empty on object, array or string');
internals.assert(this, (typeof this._ref === 'object' && this._ref !== null) || typeof this._ref === 'string', 'Can only assert length on object, array or string');

const length = this._ref.length !== undefined ? this._ref.length : Object.keys(this._ref).length;
return this.assert(length === size, 'have a length of ' + size, length);
Expand Down
14 changes: 14 additions & 0 deletions test/index.js
Expand Up @@ -1445,6 +1445,20 @@ describe('expect()', () => {

Hoek.assert(exception.message === 'Expected \'a\' to have a length of 10 but got 1', exception);
});

it('throws on length check on objects with no length property', (done) => {

let exception = false;
try {
Code.expect(null).to.have.length(2);
}
catch (err) {
exception = err;
}

Hoek.assert(exception.message === 'Can only assert length on object, array or string', exception);
done();
});
});

describe('equal()', () => {
Expand Down

0 comments on commit bece7c3

Please sign in to comment.