Add fp.findFrom and fp.findLastFrom tests.

This commit is contained in:
John-David Dalton
2016-05-21 19:56:47 -07:00
parent 40c5a6af49
commit 6fe020c920

View File

@@ -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) {