mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Add lazy at tests to ensure it works with string index values.
This commit is contained in:
@@ -13896,7 +13896,7 @@
|
|||||||
LazyWrapper.prototype.at = rest(function(paths) {
|
LazyWrapper.prototype.at = rest(function(paths) {
|
||||||
paths = baseFlatten(paths);
|
paths = baseFlatten(paths);
|
||||||
return (paths.length == 1 && isIndex(paths[0]))
|
return (paths.length == 1 && isIndex(paths[0]))
|
||||||
? this.slice(paths[0], paths[0] + 1)
|
? this.slice(paths[0], +paths[0] + 1)
|
||||||
: new LazyWrapper(this);
|
: new LazyWrapper(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
25
test/test.js
25
test/test.js
@@ -1248,13 +1248,13 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should work in a lazy chain sequence', function(assert) {
|
QUnit.test('should work in a lazy chain sequence', function(assert) {
|
||||||
assert.expect(4);
|
assert.expect(6);
|
||||||
|
|
||||||
if (!isNpm) {
|
if (!isNpm) {
|
||||||
var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
|
var largeArray = lodashStable.range(LARGE_ARRAY_SIZE),
|
||||||
smallArray = array;
|
smallArray = array;
|
||||||
|
|
||||||
lodashStable.each([[2], [2, 1]], function(paths) {
|
lodashStable.each([[2], ['2'], [2, 1]], function(paths) {
|
||||||
lodashStable.times(2, function(index) {
|
lodashStable.times(2, function(index) {
|
||||||
var array = index ? largeArray : smallArray,
|
var array = index ? largeArray : smallArray,
|
||||||
wrapped = _(array).map(identity).at(paths);
|
wrapped = _(array).map(identity).at(paths);
|
||||||
@@ -1264,24 +1264,29 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(assert, 4);
|
skipTest(assert, 6);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should support shortcut fusion', function(assert) {
|
QUnit.test('should support shortcut fusion', function(assert) {
|
||||||
assert.expect(2);
|
assert.expect(4);
|
||||||
|
|
||||||
if (!isNpm) {
|
if (!isNpm) {
|
||||||
var count = 0,
|
var array = lodashStable.range(LARGE_ARRAY_SIZE),
|
||||||
array = lodashStable.range(LARGE_ARRAY_SIZE),
|
count = 0,
|
||||||
iteratee = function(value) { count++; return square(value); },
|
iteratee = function(value) { count++; return square(value); },
|
||||||
actual = _(array).map(iteratee).at(LARGE_ARRAY_SIZE - 1).value();
|
lastIndex = LARGE_ARRAY_SIZE - 1;
|
||||||
|
|
||||||
assert.strictEqual(count, 1);
|
_.each([lastIndex, lastIndex + ''], function(index) {
|
||||||
assert.deepEqual(actual, [square(LARGE_ARRAY_SIZE -1)]);
|
count = 0;
|
||||||
|
var actual = _(array).map(iteratee).at(index).value();
|
||||||
|
|
||||||
|
assert.strictEqual(count, 1);
|
||||||
|
assert.deepEqual(actual, [square(lastIndex)]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(assert, 2);
|
skipTest(assert, 4);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user