From 51d97616093903434a0f20308529d06cbc74c6cf Mon Sep 17 00:00:00 2001 From: asbish Date: Sun, 11 Feb 2018 23:27:02 +0900 Subject: [PATCH] doc: Fix about .lengthOf --- lib/chai/core/assertions.js | 34 +++++++++++++++------------------- lib/chai/interface/assert.js | 4 +++- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/chai/core/assertions.js b/lib/chai/core/assertions.js index ccdfdb9c7..fe86cfbd0 100644 --- a/lib/chai/core/assertions.js +++ b/lib/chai/core/assertions.js @@ -1102,8 +1102,8 @@ module.exports = function (chai, _) { * expect(2).to.equal(2); // Recommended * expect(2).to.be.above(1); // Not recommended * - * Add `.lengthOf` earlier in the chain to assert that the value of the - * target's `length` property is greater than the given number `n`. + * Add `.lengthOf` earlier in the chain to assert that the target's `length` + * or `size` is greater than the given number `n`. * * expect('foo').to.have.lengthOf(3); // Recommended * expect('foo').to.have.lengthOf.above(2); // Not recommended @@ -1207,9 +1207,8 @@ module.exports = function (chai, _) { * expect(2).to.be.at.least(1); // Not recommended * expect(2).to.be.at.least(2); // Not recommended * - * Add `.lengthOf` earlier in the chain to assert that the value of the - * target's `length` property is greater than or equal to the given number - * `n`. + * Add `.lengthOf` earlier in the chain to assert that the target's `length` + * or `size` is greater than or equal to the given number `n`. * * expect('foo').to.have.lengthOf(3); // Recommended * expect('foo').to.have.lengthOf.at.least(2); // Not recommended @@ -1309,8 +1308,8 @@ module.exports = function (chai, _) { * expect(1).to.equal(1); // Recommended * expect(1).to.be.below(2); // Not recommended * - * Add `.lengthOf` earlier in the chain to assert that the value of the - * target's `length` property is less than the given number `n`. + * Add `.lengthOf` earlier in the chain to assert that the target's `length` + * or `size` is less than the given number `n`. * * expect('foo').to.have.lengthOf(3); // Recommended * expect('foo').to.have.lengthOf.below(4); // Not recommended @@ -1414,8 +1413,8 @@ module.exports = function (chai, _) { * expect(1).to.be.at.most(2); // Not recommended * expect(1).to.be.at.most(1); // Not recommended * - * Add `.lengthOf` earlier in the chain to assert that the value of the - * target's `length` property is less than or equal to the given number `n`. + * Add `.lengthOf` earlier in the chain to assert that the target's `length` + * or `size` is less than or equal to the given number `n`. * * expect('foo').to.have.lengthOf(3); // Recommended * expect('foo').to.have.lengthOf.at.most(4); // Not recommended @@ -1518,9 +1517,9 @@ module.exports = function (chai, _) { * expect(2).to.be.within(2, 3); // Not recommended * expect(2).to.be.within(1, 2); // Not recommended * - * Add `.lengthOf` earlier in the chain to assert that the value of the - * target's `length` property is greater than or equal to the given number - * `start`, and less than or equal to the given number `finish`. + * Add `.lengthOf` earlier in the chain to assert that the target's `length` + * or `size` is greater than or equal to the given number `start`, and less + * than or equal to the given number `finish`. * * expect('foo').to.have.lengthOf(3); // Recommended * expect('foo').to.have.lengthOf.within(2, 4); // Not recommended @@ -2042,16 +2041,13 @@ module.exports = function (chai, _) { /** * ### .lengthOf(n[, msg]) * - * Asserts that the target's `length` property is equal to the given number + * Asserts that the target's `length` or `size` is equal to the given number * `n`. * * expect([1, 2, 3]).to.have.lengthOf(3); * expect('foo').to.have.lengthOf(3); - * - * When the target is a map or set, asserts that the target's `size` property. - * - * expect(new Set([1, 2])).to.hove.lengthOf(2); - * expect(new Map([['a', 1], ['b', 2]])).to.hove.lengthOf(2); + * expect(new Set([1, 2, 3])).to.have.lengthOf(3); + * expect(new Map([['a', 1], ['b', 2], ['c', 3]])).to.have.lengthOf(3); * * Add `.not` earlier in the chain to negate `.lengthOf`. However, it's often * best to assert that the target's `length` property is equal to its expected @@ -2125,7 +2121,7 @@ module.exports = function (chai, _) { } this.assert( - itemsCount == n + itemsCount == n , 'expected #{this} to have a ' + descriptor + ' of #{exp} but got #{act}' , 'expected #{this} to not have a ' + descriptor + ' of #{act}' , n diff --git a/lib/chai/interface/assert.js b/lib/chai/interface/assert.js index 5f46c804c..9c0ab0a15 100644 --- a/lib/chai/interface/assert.js +++ b/lib/chai/interface/assert.js @@ -1664,10 +1664,12 @@ module.exports = function (chai, util) { /** * ### .lengthOf(object, length, [message]) * - * Asserts that `object` has a `length` property with the expected value. + * Asserts that `object` has a `length` or `size` with the expected value. * * assert.lengthOf([1,2,3], 3, 'array has length of 3'); * assert.lengthOf('foobar', 6, 'string has length of 6'); + * assert.lengthOf(new Set([1,2,3]), 3, 'set has size of 3'); + * assert.lengthOf(new Map([['a',1],['b',2],['c',3]]), 3, 'map has size of 3'); * * @name lengthOf * @param {Mixed} object