mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57:49 +00:00
Add _.nth and _.nthArg tests.
This commit is contained in:
50
test/test.js
50
test/test.js
@@ -15894,6 +15894,35 @@
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
QUnit.test('should return `undefined` for empty arrays', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var values = [null, undefined, []],
|
||||
expected = lodashStable.map(values, noop);
|
||||
|
||||
var actual = lodashStable.map(values, function(array) {
|
||||
return _.nth(array, 1);
|
||||
});
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
QUnit.test('should return `undefined` for non-indexes', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var array = [1, 2],
|
||||
values = [Infinity, array.length],
|
||||
expected = lodashStable.map(values, noop);
|
||||
|
||||
array[-1] = 3;
|
||||
|
||||
var actual = lodashStable.map(values, function(n) {
|
||||
return _.nth(array, n);
|
||||
});
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@@ -15948,6 +15977,27 @@
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
QUnit.test('should return `undefined` for empty arrays', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var func = _.nthArg(1);
|
||||
assert.strictEqual(func(), undefined);
|
||||
});
|
||||
|
||||
QUnit.test('should return `undefined` for non-indexes', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var values = [Infinity, args.length],
|
||||
expected = lodashStable.map(values, noop);
|
||||
|
||||
var actual = lodashStable.map(values, function(n) {
|
||||
var func = _.nthArg(n);
|
||||
return func.apply(undefined, args);
|
||||
});
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user