From 6fe020c920d46b5786cf7c3c504527a4bc263b04 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 21 May 2016 19:56:47 -0700 Subject: [PATCH] Add `fp.findFrom` and `fp.findLastFrom` tests. --- test/test-fp.js | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/test/test-fp.js b/test/test-fp.js index 36db6597b..f811fd7c0 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -1097,9 +1097,9 @@ /*--------------------------------------------------------------------------*/ - QUnit.module('fp.findIndexFrom methods'); + QUnit.module('fp.findFrom methods'); - _.each(['findIndexFrom', 'findLastIndexFrom'], function(methodName) { + _.each(['findFrom', 'findIndexFrom', 'findLastFrom', 'findLastIndexFrom'], function(methodName) { var func = fp[methodName]; QUnit.test('`_.' + methodName + '` should provide the correct `predicate` arguments', function(assert) { @@ -1117,6 +1117,44 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('fp.findFrom'); + + (function() { + function resolve(value) { + return fp.flow(fp.property('a'), fp.eq(value)); + } + + QUnit.test('should have an argument order of `value`, `fromIndex`, then `array`', function(assert) { + assert.expect(2); + + var objects = [{ 'a': 1 }, { 'a': 2 }, { 'a': 1 }, { 'a': 2 }]; + + assert.strictEqual(fp.findFrom(resolve(1))(1)(objects), objects[2]); + assert.strictEqual(fp.findFrom(resolve(2))(-2)(objects), objects[3]); + }); + }()); + + /*--------------------------------------------------------------------------*/ + + QUnit.module('fp.findLastFrom'); + + (function() { + function resolve(value) { + return fp.flow(fp.property('a'), fp.eq(value)); + } + + QUnit.test('should have an argument order of `value`, `fromIndex`, then `array`', function(assert) { + assert.expect(2); + + var objects = [{ 'a': 1 }, { 'a': 2 }, { 'a': 1 }, { 'a': 2 }]; + + assert.strictEqual(fp.findLastFrom(resolve(1))(1)(objects), objects[0]); + assert.strictEqual(fp.findLastFrom(resolve(2))(-2)(objects), objects[1]); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('fp.findIndexFrom and fp.indexOfFrom'); _.each(['findIndexFrom', 'indexOfFrom'], function(methodName) {