From 639c8d4171bf8a7b98eda400e618aa63b71c72bb Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 27 Mar 2013 07:55:19 -0700 Subject: [PATCH] Add `_.forEach` `thisArg` unit test to test.js. Former-commit-id: b3d16d90789e76df778ac3457f68fdcbc3f6f4ad --- test/test-build.js | 17 ++++++----------- test/test.js | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/test/test-build.js b/test/test-build.js index e0c38d6f1..ce28577b0 100644 --- a/test/test-build.js +++ b/test/test-build.js @@ -878,10 +878,11 @@ deepEqual(lodash.defaults({}, new Foo), Foo.prototype, '_.defaults should assign inherited `source` properties: ' + basename); deepEqual(lodash.extend({}, new Foo), Foo.prototype, '_.extend should assign inherited `source` properties: ' + basename); - actual = lodash.extend({}, { 'a': 0 }, function(a, b) { - return this[b]; - }, [2]); + var callback = function(a, b) { + actual = this[b]; + }; + actual = lodash.extend({}, { 'a': 0 }, callback, [2]); strictEqual(actual.a, 0, '_.extend should ignore `callback` and `thisArg`: ' + basename); actual = lodash.find(array, function(value) { @@ -899,16 +900,10 @@ equal(last, _.last(array), '_.forEach should not exit early: ' + basename); equal(actual, undefined, '_.forEach should return `undefined`: ' + basename); - lodash.forEach([1], function(value, index) { - actual = this[index]; - }, [2]); - + lodash.forEach([1], callback, [2]); equal(actual, 2, '_.forEach supports the `thisArg` argument when iterating arrays: ' + basename); - lodash.forEach({ 'a': 1 }, function(value, key) { - actual = this[key]; - }, { 'a': 2 }); - + lodash.forEach({ 'a': 1 }, callback, { 'a': 2 }); equal(actual, 2, '_.forEach supports the `thisArg` argument when iterating objects: ' + basename); array = [{ 'a': [1, 2] }, { 'a': [3] }]; diff --git a/test/test.js b/test/test.js index 86988c521..216f590f6 100644 --- a/test/test.js +++ b/test/test.js @@ -865,6 +865,20 @@ equal(wrapper.forEach(Boolean), wrapper); }); + test('supports the `thisArg` argument', function() { + var actual; + + function callback(value, index) { + actual = this[index]; + } + + _.forEach([1], callback, [2]); + equal(actual, 2); + + _.forEach({ 'a': 1 }, callback, { 'a': 2 }); + equal(actual, 2); + }); + _.each({ 'literal': 'abc', 'object': Object('abc')