mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Ensure reverse returns a LodashWrapper instance when chaining.
This commit is contained in:
@@ -4982,12 +4982,10 @@
|
|||||||
* // => [3, 2, 1]
|
* // => [3, 2, 1]
|
||||||
*/
|
*/
|
||||||
function wrapperReverse() {
|
function wrapperReverse() {
|
||||||
var wrapped = this.__wrapped__;
|
var value = this.__wrapped__;
|
||||||
|
if (value instanceof LazyWrapper) {
|
||||||
if(wrapped instanceof LazyWrapper) {
|
return new LodashWrapper(value.reverse());
|
||||||
return wrapped.reverse();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.thru(function(value) {
|
return this.thru(function(value) {
|
||||||
return value.reverse();
|
return value.reverse();
|
||||||
});
|
});
|
||||||
|
|||||||
29
test/test.js
29
test/test.js
@@ -12928,38 +12928,39 @@
|
|||||||
QUnit.module('lodash(...).reverse');
|
QUnit.module('lodash(...).reverse');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
test('should return the wrapped reversed `array`', 2, function() {
|
test('should return the wrapped reversed `array`', 3, function() {
|
||||||
if (!isNpm) {
|
if (!isNpm) {
|
||||||
var array = [1, 2, 3],
|
var array = [1, 2, 3],
|
||||||
wrapped = _(array).reverse(),
|
wrapper = _(array).reverse(),
|
||||||
actual = wrapped.value();
|
actual = wrapper.value();
|
||||||
|
|
||||||
|
ok(wrapper instanceof _);
|
||||||
strictEqual(actual, array);
|
strictEqual(actual, array);
|
||||||
deepEqual(actual, [3, 2, 1]);
|
deepEqual(actual, [3, 2, 1]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(2);
|
skipTest(3);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should be lazy when in a lazy chain sequence', 2, function() {
|
||||||
test('should be lazy when in a lazy chain sequence', 1, function() {
|
|
||||||
if (!isNpm) {
|
if (!isNpm) {
|
||||||
var spy = {
|
var spy = {
|
||||||
toString: function () {
|
'toString': function() {
|
||||||
throw new Error("Spy was revealed");
|
throw new Error('Spy was revealed');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var actual = _(["a", spy])
|
try {
|
||||||
.map(String)
|
var wrapper = _(['a', spy]).map(String).reverse(),
|
||||||
.reverse()
|
actual = wrapper.last();
|
||||||
.last();
|
} catch(e) {}
|
||||||
|
|
||||||
strictEqual(actual, "a");
|
ok(wrapper instanceof _);
|
||||||
|
strictEqual(actual, 'a');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(1);
|
skipTest(2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|||||||
Reference in New Issue
Block a user