From 7cb47c849487c72bd84170ac25a2478fa2f32087 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 27 May 2014 23:21:03 -0400 Subject: [PATCH] Add chaining tests to string methods. --- test/test.js | 49 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/test/test.js b/test/test.js index e26677141..e0b287141 100644 --- a/test/test.js +++ b/test/test.js @@ -4057,6 +4057,19 @@ deepEqual(_.invert(object), { 'hasOwnProperty': 'a', 'constructor': 'b' }); ok(_.isEqual(_.invert(object, true), { 'hasOwnProperty': ['a'], 'constructor': ['b'] })); }); + + test('should return a wrapped value when chaining', 2, function() { + if (!isNpm) { + var object = { 'a': 1, 'b': 2 }, + actual = _(object).invert(); + + ok(actual instanceof _); + deepEqual(actual.value(), { '1': 'a', '2': 'b' }); + } + else { + skipTest(2); + } + }); }()); /*--------------------------------------------------------------------------*/ @@ -9766,8 +9779,10 @@ parts = parts.join(' and '); test('`_.' + methodName + '` should remove ' + parts + ' whitespace', 1, function() { - var string = whitespace + 'a b c' + whitespace; - strictEqual(func(string), (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '')); + var string = whitespace + 'a b c' + whitespace, + expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : ''); + + strictEqual(func(string), expected); }); test('`_.' + methodName + '` should not remove non-whitespace characters', 1, function() { @@ -9778,20 +9793,25 @@ }); test('`_.' + methodName + '` should coerce `string` to a string', 1, function() { - var object = { 'toString': function() { return whitespace + 'a b c' + whitespace; } }; - strictEqual(func(object), (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '')); + var object = { 'toString': function() { return whitespace + 'a b c' + whitespace; } }, + expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : ''); + + strictEqual(func(object), expected); }); test('`_.' + methodName + '` should remove ' + parts + ' `chars`', 1, function() { - var string = '-_-a-b-c-_-'; - strictEqual(func(string, '_-'), (index == 2 ? '-_-' : '') + 'a-b-c' + (index == 1 ? '-_-' : '')); + var string = '-_-a-b-c-_-', + expected = (index == 2 ? '-_-' : '') + 'a-b-c' + (index == 1 ? '-_-' : ''); + + strictEqual(func(string, '_-'), expected); }); test('`_.' + methodName + '` should coerce `chars` to a string', 1, function() { var object = { 'toString': function() { return '_-'; } }, - string = '-_-a-b-c-_-'; + string = '-_-a-b-c-_-', + expected = (index == 2 ? '-_-' : '') + 'a-b-c' + (index == 1 ? '-_-' : ''); - strictEqual(func(string, object), (index == 2 ? '-_-' : '') + 'a-b-c' + (index == 1 ? '-_-' : '')); + strictEqual(func(string, object), expected); }); test('`_.' + methodName + '` should return an empty string when provided `null`, `undefined`, or empty string and `chars`', 6, function() { @@ -9810,6 +9830,19 @@ strictEqual(func(string, undefined), expected); strictEqual(func(string, ''), string); }); + + test('`_.' + methodName + '` should return an unwrapped value when chaining', 1, function() { + if (!isNpm) { + var string = whitespace + 'a b c' + whitespace, + expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : ''), + actual = _(string)[methodName](); + + strictEqual(actual, expected); + } + else { + skipTest(); + } + }); }); /*--------------------------------------------------------------------------*/