From c44cd76c5ac07a57a059e23f9377b730c06dc7bf Mon Sep 17 00:00:00 2001 From: jdalton Date: Wed, 11 Feb 2015 08:29:01 -0800 Subject: [PATCH] Ensure `commit and `reverse` track `__chain__` settings. [closes #958] --- lodash.src.js | 4 ++-- test/test.js | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lodash.src.js b/lodash.src.js index 91ec72e8a..d9493dec6 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -5570,7 +5570,7 @@ * // => [1, 2, 3] */ function wrapperCommit() { - return new LodashWrapper(this.value()); + return new LodashWrapper(this.value(), this.__chain__); } /** @@ -5638,7 +5638,7 @@ if (this.__actions__.length) { value = new LazyWrapper(this); } - return new LodashWrapper(value.reverse()); + return new LodashWrapper(value.reverse(), this.__chain__); } return this.thru(function(value) { return value.reverse(); diff --git a/test/test.js b/test/test.js index f5e158f3f..caf183654 100644 --- a/test/test.js +++ b/test/test.js @@ -14570,6 +14570,17 @@ skipTest(4); } }); + + test('should track the `__chain__` value of a wrapper', 2, function() { + if (!isNpm) { + var wrapper = _([1]).chain().commit().first(); + ok(wrapper instanceof _); + strictEqual(wrapper.value(), 1); + } + else { + skipTest(2); + } + }); }()); /*--------------------------------------------------------------------------*/ @@ -14745,6 +14756,17 @@ skipTest(4); } }); + + test('should track the `__chain__` value of a wrapper', 2, function() { + if (!isNpm) { + var wrapper = _([1, 2, 3]).chain().reverse().first(); + ok(wrapper instanceof _); + strictEqual(wrapper.value(), 3); + } + else { + skipTest(2); + } + }); }()); /*--------------------------------------------------------------------------*/