From 5f7dcc9b78051775789fbfffb0fdadd66a0eecef Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 21 Nov 2014 01:33:38 -0800 Subject: [PATCH] Add lazy `_.compact` test and cleanup previous fix. --- lodash.js | 4 +++- test/test.js | 17 ++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lodash.js b/lodash.js index a9d86c9e4..9168d2cad 100644 --- a/lodash.js +++ b/lodash.js @@ -10266,7 +10266,9 @@ : lodash[methodName](this.value()); } if (isLazy || isArray(value)) { - var result = func.apply(isLazy && !this.__queue__.length ? value : new LazyWrapper(this), args); + var wrapper = (isLazy && !this.__queue__.length) ? value : new LazyWrapper(this), + result = func.apply(wrapper, args); + return new LodashWrapper(result, chainAll); } return this.thru(function(value) { diff --git a/test/test.js b/test/test.js index 586022eb4..1e397a338 100644 --- a/test/test.js +++ b/test/test.js @@ -1894,9 +1894,10 @@ deepEqual(_.compact(falsey.concat(array)), array); }); - test('should filter falsey values when in between lazy operators', 1, function () { + test('should return a wrapped value when chaining', 2, function() { if (!isNpm) { - var wrapped = _(falsey).map(_.identity).compact().map(_.identity); + var wrapped = _(falsey).compact(); + ok(wrapped instanceof _); deepEqual(wrapped.value(), []); } else { @@ -1904,11 +1905,13 @@ } }); - test('should return a wrapped value when chaining', 2, function() { + test('should work when in between lazy operators', 2, function() { if (!isNpm) { - var wrapped = _(falsey).compact(); - ok(wrapped instanceof _); - deepEqual(wrapped.value(), []); + var actual = _(falsey).map().compact().map().value(); + deepEqual(actual, []); + + actual = _(falsey).map().push(true, 1).compact().push('a').map().value(); + deepEqual(actual, [true, 1, 'a']); } else { skipTest(2); @@ -3565,7 +3568,7 @@ }); test('should return `true` if `predicate` returns truthy for all elements in the collection', 1, function() { - strictEqual(_.every([true, 1, 'x'], _.identity), true); + strictEqual(_.every([true, 1, 'a'], _.identity), true); }); test('should return `false` as soon as `predicate` returns falsey', 1, function() {