Ensure _.first and _.last have the correct chaining behavior when passing a callback and thisArg.

Former-commit-id: 4d54fd677fa48bf8de033696c58ee66babd77a81
This commit is contained in:
John-David Dalton
2013-01-16 01:39:58 -08:00
parent b60d0cdb17
commit ab83f2d5e2
4 changed files with 53 additions and 5 deletions

View File

@@ -640,6 +640,29 @@
deepEqual(actual, [1, 2]);
});
test('should chain when passing `n`, `callback`, or `thisArg`', function() {
var actual = _(array).first(2);
ok(actual instanceof _);
actual = _(array).first(function(num) {
return num < 3;
});
ok(actual instanceof _);
actual = _(array).first(function(value, index) {
return this[index] < 3;
}, array);
ok(actual instanceof _);
});
test('should not chain when no arguments are passed', function() {
var actual = _(array).first();
strictEqual(actual, 1);
});
}());
/*--------------------------------------------------------------------------*/
@@ -1192,6 +1215,29 @@
deepEqual(actual, [2, 3]);
});
test('should chain when passing `n`, `callback`, or `thisArg`', function() {
var actual = _(array).last(2);
ok(actual instanceof _);
actual = _(array).last(function(num) {
return num > 1;
});
ok(actual instanceof _);
actual = _(array).last(function(value, index) {
return this[index] > 1;
}, array);
ok(actual instanceof _);
});
test('should not chain when no arguments are passed', function() {
var actual = _(array).last();
equal(actual, 3);
});
}());
/*--------------------------------------------------------------------------*/