mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 08:07:50 +00:00
Ensure _.first and _.last have the correct chaining behavior when passing a callback and thisArg.
Former-commit-id: 4d54fd677fa48bf8de033696c58ee66babd77a81
This commit is contained in:
46
test/test.js
46
test/test.js
@@ -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);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user