From bf1c54e5a308cdb1cef48bb6bc6a78861d826ba5 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 13 Oct 2014 00:36:34 -0700 Subject: [PATCH] Add lazy `_.filter` and `_.reject` tests. --- test/test.js | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/test/test.js b/test/test.js index e62b34313..10a342b2d 100644 --- a/test/test.js +++ b/test/test.js @@ -3110,7 +3110,7 @@ test('should work in a lazy chain sequence', 2, function() { if (!isNpm) { var array = [1, 2, 3, 4], - predicate = function(value) {return value > 1; }, + predicate = function(value) { return value > 1; }, actual = _(array).filter(predicate).drop(2).value(); deepEqual(actual, [4]); @@ -3180,7 +3180,7 @@ test('should work in a lazy chain sequence', 2, function() { if (!isNpm) { var array = [1, 2, 3, 4], - predicate = function(value) {return value < 4; }, + predicate = function(value) { return value < 4; }, actual = _(array).filter(predicate).dropRight(2).value(); deepEqual(actual, [1]); @@ -3759,7 +3759,7 @@ test('should work in a lazy chain sequence', 2, function() { if (!isNpm) { var array = [1, 2, 3, 4], - predicate = function(value) {return value > 1; }, + predicate = function(value) { return value > 1; }, actual = _(array).filter(predicate).take().value(); deepEqual(actual, [2]); @@ -3829,7 +3829,7 @@ test('should work in a lazy chain sequence', 2, function() { if (!isNpm) { var array = [1, 2, 3, 4], - predicate = function(value) {return value < 4; }, + predicate = function(value) { return value < 4; }, actual = _(array).filter(predicate).takeRight().value(); deepEqual(actual, [3]); @@ -9476,17 +9476,38 @@ QUnit.module('filter methods'); - _.each(['filter', 'reject'], function(methodNames) { - var func = _[methodNames]; + _.each(['filter', 'reject'], function(methodName) { + var func = _[methodName], + isFilter = methodName == 'filter'; - test('`_.' + methodNames + '` should not modify the resulting value from within `callback`', 1, function() { + test('`_.' + methodName + '` should not modify the resulting value from within `callback`', 1, function() { var actual = func([0], function(num, index, array) { array[index] = 1; - return methodNames == 'filter'; + return isFilter; }); deepEqual(actual, [0]); }); + + test('`_.' + methodName + '` should work in a lazy chain sequence', 2, function() { + if (!isNpm) { + var array = [1, 2, 3], + object = { 'a': 1, 'b': 2, 'c': 3 }, + doubled = function(value) { return value * 2; }, + predicate = function(value) { return isFilter ? (value > 3) : (value < 3); }; + + var expected = [4, 6], + actual = _(array).map(doubled)[methodName](predicate).value(); + + deepEqual(actual, expected); + + actual = _(object).mapValues(doubled)[methodName](predicate).value(); + deepEqual(actual, expected); + } + else { + skipTest(2); + } + }); }); /*--------------------------------------------------------------------------*/