From 0f201e3fd8c95808e11b418952db204a72cf89d7 Mon Sep 17 00:00:00 2001 From: jdalton Date: Sat, 7 Mar 2015 00:23:56 -0800 Subject: [PATCH] Add more chaining tests `join`, `replace`, & `split`. --- test/test.js | 60 +++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/test/test.js b/test/test.js index f3f578ac6..32df338b7 100644 --- a/test/test.js +++ b/test/test.js @@ -15571,19 +15571,27 @@ QUnit.module('lodash(...).join'); (function() { + var array = [1, 2, 3]; + test('should return join all array elements into a string', 2, function() { if (!isNpm) { - var array = [1, 2, 3], - wrapped = _(array), - actual = wrapped.join('.'); - - strictEqual(actual, '1.2.3'); + var wrapped = _(array); + strictEqual(wrapped.join('.'), '1.2.3'); strictEqual(wrapped.value(), array); } else { skipTest(2); } }); + + test('should return a wrapped value when explicitly chaining', 1, function() { + if (!isNpm) { + ok(_(array).chain().join('.') instanceof _); + } + else { + skipTest(); + } + }); }()); /*--------------------------------------------------------------------------*/ @@ -15656,18 +15664,25 @@ QUnit.module('lodash(...).replace'); (function() { - test('should support string replace', 2, function() { + test('should replace the matched pattern', 2, function() { if (!isNpm) { - var string = 'hi hidash', - wrapped = _(string); - - deepEqual(wrapped.replace('hi', 'lo').value(), 'lo hidash'); - deepEqual(wrapped.replace(/hi/g, 'lo').value(), 'lo lodash'); + var wrapped = _('abcdef'); + strictEqual(wrapped.replace('def', '123'), 'abc123'); + strictEqual(wrapped.replace(/[bdf]/g, '-'), 'a-c-e-'); } else { skipTest(2); } }); + + test('should return a wrapped value when explicitly chaining', 1, function() { + if (!isNpm) { + ok(_('abc').chain().replace('b', '_') instanceof _); + } + else { + skipTest(); + } + }); }()); /*--------------------------------------------------------------------------*/ @@ -15844,31 +15859,24 @@ QUnit.module('lodash(...).split'); (function() { - test('should support string split', 1, function() { + test('should support string split', 2, function() { if (!isNpm) { - var string = 'hi ya', - wrapped = _(string), - actual = ['hi', 'ya']; - - deepEqual(wrapped.split(' ').value(), actual); + var wrapped = _('abcde'); + deepEqual(wrapped.split('c').value(), ['ab', 'de']); + deepEqual(wrapped.split(/[bd]/).value(), ['a', 'c', 'e']); } else { - skipTest(1); + skipTest(2); } }); - }()); - (function() { test('should allow mixed string and array prototype methods', 1, function() { if (!isNpm) { - var string = 'hi ya', - wrapped = _(string), - actual = 'hi,ya'; - - deepEqual(wrapped.split(' ').join(','), actual); + var wrapped = _('abc'); + strictEqual(wrapped.split('b').join(','), 'a,c'); } else { - skipTest(1); + skipTest(); } }); }());