mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 19:37:49 +00:00
Add lazy tests for _.first and _.last.
This commit is contained in:
41
test/test.js
41
test/test.js
@@ -3702,7 +3702,9 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should return `undefined` when querying empty arrays', 1, function() {
|
test('should return `undefined` when querying empty arrays', 1, function() {
|
||||||
strictEqual(_.first([]), undefined);
|
var array = [];
|
||||||
|
array['-1'] = 1;
|
||||||
|
strictEqual(_.first(array), undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should work as an iteratee for `_.map`', 1, function() {
|
test('should work as an iteratee for `_.map`', 1, function() {
|
||||||
@@ -3721,6 +3723,21 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should work in a lazy chain sequence', 1, function() {
|
||||||
|
if (!isNpm) {
|
||||||
|
var array = [1, 2, 3, 4];
|
||||||
|
|
||||||
|
var wrapped = _(array).filter(function(value) {
|
||||||
|
return value % 2 == 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
strictEqual(wrapped.first(), 2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipTest();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test('should be aliased', 1, function() {
|
test('should be aliased', 1, function() {
|
||||||
strictEqual(_.head, _.first);
|
strictEqual(_.head, _.first);
|
||||||
});
|
});
|
||||||
@@ -7033,7 +7050,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should return `undefined` when querying empty arrays', 1, function() {
|
test('should return `undefined` when querying empty arrays', 1, function() {
|
||||||
var array = []
|
var array = [];
|
||||||
array['-1'] = 1;
|
array['-1'] = 1;
|
||||||
strictEqual(_.last([]), undefined);
|
strictEqual(_.last([]), undefined);
|
||||||
});
|
});
|
||||||
@@ -7053,6 +7070,21 @@
|
|||||||
skipTest();
|
skipTest();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should work in a lazy chain sequence', 1, function() {
|
||||||
|
if (!isNpm) {
|
||||||
|
var array = [1, 2, 3, 4];
|
||||||
|
|
||||||
|
var wrapped = _(array).filter(function(value) {
|
||||||
|
return value % 2;
|
||||||
|
});
|
||||||
|
|
||||||
|
strictEqual(wrapped.last(), 3);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipTest();
|
||||||
|
}
|
||||||
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
@@ -8130,11 +8162,10 @@
|
|||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
test('should create a function that negates the result of `func`', 2, function() {
|
test('should create a function that negates the result of `func`', 2, function() {
|
||||||
function isEven(n) {
|
var negate = _.negate(function(n) {
|
||||||
return n % 2 == 0;
|
return n % 2 == 0;
|
||||||
}
|
});
|
||||||
|
|
||||||
var negate = _.negate(isEven);
|
|
||||||
strictEqual(negate(1), true);
|
strictEqual(negate(1), true);
|
||||||
strictEqual(negate(2), false);
|
strictEqual(negate(2), false);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user