8000 Add `_.forEach` `thisArg` unit test to test.js. · lodash/lodash@639c8d4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 639c8d4

Browse files
committed
Add _.forEach thisArg unit test to test.js.
Former-commit-id: b3d16d90789e76df778ac3457f68fdcbc3f6f4ad
1 parent d77c9d3 commit 639c8d4

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

test/test-build.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -878,10 +878,11 @@
878878
deepEqual(lodash.defaults({}, new Foo), Foo.prototype, '_.defaults should assign inherited `source` properties: ' + basename);
879879
deepEqual(lodash.extend({}, new Foo), Foo.prototype, '_.extend should assign inherited `source` properties: ' + basename);
880880

881-
actual = lodash.extend({}, { 'a': 0 }, function(a, b) {
882-
return this[b];
883-
}, [2]);
881+
var callback = function(a, b) {
882+
actual = this[b];
883+
};
884884

885+
actual = lodash.extend({}, { 'a': 0 }, callback, [2]);
885886
strictEqual(actual.a, 0, '_.extend should ignore `callback` and `thisArg`: ' + basename);
886887

887888
actual = lodash.find(array, function(value) {
@@ -899,16 +900,10 @@
899900
equal(last, _.last(array), '_.forEach should not exit early: ' + basename);
900901
equal(actual, undefined, '_.forEach should return `undefined`: ' + basename);
901902

902-
lodash.forEach([1], function(value, index) {
903-
actual = this[index];
904-
}, [2]);
905-
903+
lodash.forEach([1], callback, [2]);
906904
equal(actual, 2, '_.forEach supports the `thisArg` argument when iterating arrays: ' + basename);
907905

908-
lodash.forEach({ 'a': 1 }, function(value, key) {
909-
actual = this[key];
910-
}, { 'a': 2 });
911-
906+
lodash.forEach({ 'a': 1 }, callback, { 'a': 2 });
912907
equal(actual, 2, '_.forEach supports the `thisArg` argument when iterating objects: ' + basename);
913908

914909
array = [{ 'a': [1, 2] }, { 'a': [3] }];

test/test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,20 @@
865865
equal(wrapper.forEach(Boolean), wrapper);
866866
});
867867

868+
test('supports the `thisArg` argument', function() {
869+
var actual;
870+
871+
function callback(value, index) {
872+
actual = this[index];
873+
}
874+
875+
_.forEach([1], callback, [2]);
876+
equal(actual, 2);
877+
878+
_.forEach({ 'a': 1 }, callback, { 'a': 2 });
879+
equal(actual, 2);
880+
});
881+
868882
_.each({
869883
'literal': 'abc',
870884
'object': Object('abc')

0 commit comments

Comments
 (0)
0