diff --git a/lodash.js b/lodash.js index 19023f4e2..9f6961dd9 100644 --- a/lodash.js +++ b/lodash.js @@ -4982,12 +4982,10 @@ * // => [3, 2, 1] */ function wrapperReverse() { - var wrapped = this.__wrapped__; - - if(wrapped instanceof LazyWrapper) { - return wrapped.reverse(); + var value = this.__wrapped__; + if (value instanceof LazyWrapper) { + return new LodashWrapper(value.reverse()); } - return this.thru(function(value) { return value.reverse(); }); diff --git a/test/test.js b/test/test.js index 3431def75..5401b98e7 100644 --- a/test/test.js +++ b/test/test.js @@ -12928,38 +12928,39 @@ QUnit.module('lodash(...).reverse'); (function() { - test('should return the wrapped reversed `array`', 2, function() { + test('should return the wrapped reversed `array`', 3, function() { if (!isNpm) { var array = [1, 2, 3], - wrapped = _(array).reverse(), - actual = wrapped.value(); + wrapper = _(array).reverse(), + actual = wrapper.value(); + ok(wrapper instanceof _); strictEqual(actual, array); deepEqual(actual, [3, 2, 1]); } else { - skipTest(2); + skipTest(3); } }); - - test('should be lazy when in a lazy chain sequence', 1, function() { + test('should be lazy when in a lazy chain sequence', 2, function() { if (!isNpm) { var spy = { - toString: function () { - throw new Error("Spy was revealed"); + 'toString': function() { + throw new Error('Spy was revealed'); } }; - var actual = _(["a", spy]) - .map(String) - .reverse() - .last(); + try { + var wrapper = _(['a', spy]).map(String).reverse(), + actual = wrapper.last(); + } catch(e) {} - strictEqual(actual, "a"); + ok(wrapper instanceof _); + strictEqual(actual, 'a'); } else { - skipTest(1); + skipTest(2); } }); }());