mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 17:07:49 +00:00
Add placeholder support tests for _.bind.
This commit is contained in:
36
test/test.js
36
test/test.js
@@ -799,11 +799,29 @@
|
|||||||
deepEqual(bound('c', 'd'), [object, 'a', 'b', 'c', 'd']);
|
deepEqual(bound('c', 'd'), [object, 'a', 'b', 'c', 'd']);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should create a function with a `length` of `0`', 1, function() {
|
test('should support placeholders', 4, function() {
|
||||||
|
if (_._iteratorTemplate) {
|
||||||
|
var object = {},
|
||||||
|
bound = _.bind(fn, object, _, 'b', _);
|
||||||
|
|
||||||
|
deepEqual(bound('a', 'c'), [object, 'a', 'b', 'c']);
|
||||||
|
deepEqual(bound('a'), [object, 'a', 'b', undefined]);
|
||||||
|
deepEqual(bound('a', 'c', 'd'), [object, 'a', 'b', 'c', 'd']);
|
||||||
|
deepEqual(bound(), [object, undefined, 'b', undefined]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipTest(4);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should create a function with a `length` of `0`', 2, function() {
|
||||||
var func = function(a, b, c) {},
|
var func = function(a, b, c) {},
|
||||||
bound = _.bind(fn, {});
|
bound = _.bind(fn, {});
|
||||||
|
|
||||||
strictEqual(bound.length, 0);
|
strictEqual(bound.length, 0);
|
||||||
|
|
||||||
|
bound = _.bind(fn, {}, 1);
|
||||||
|
strictEqual(bound.length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should ignore binding when called with the `new` operator', 3, function() {
|
test('should ignore binding when called with the `new` operator', 3, function() {
|
||||||
@@ -6018,24 +6036,20 @@
|
|||||||
test('`_.' + methodName + '` should support placeholders', 4, function() {
|
test('`_.' + methodName + '` should support placeholders', 4, function() {
|
||||||
if (_._iteratorTemplate) {
|
if (_._iteratorTemplate) {
|
||||||
var fn = function() {
|
var fn = function() {
|
||||||
return _.reduce(arguments, function(string, chr) {
|
return slice.call(arguments);
|
||||||
return string + (chr || '');
|
|
||||||
}, '');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var par = func(fn, _, 'b', _);
|
var par = func(fn, _, 'b', _);
|
||||||
equal(par('a', 'c'), 'abc');
|
deepEqual(par('a', 'c'), ['a', 'b', 'c']);
|
||||||
equal(par('a'), 'ab');
|
deepEqual(par('a'), ['a', 'b', undefined]);
|
||||||
|
deepEqual(par(), [undefined, 'b', undefined]);
|
||||||
|
|
||||||
if (isPartial) {
|
if (isPartial) {
|
||||||
equal(par('a', 'c', 'd'), 'abcd');
|
deepEqual(par('a', 'c', 'd'), ['a', 'b', 'c', 'd']);
|
||||||
} else {
|
} else {
|
||||||
par = func(fn, _, 'c', _);
|
par = func(fn, _, 'c', _);
|
||||||
equal(par('a', 'b', 'd'), 'abcd');
|
deepEqual(par('a', 'b', 'd'), ['a', 'b', 'c', 'd']);
|
||||||
}
|
}
|
||||||
fn = function() { return slice.call(arguments); };
|
|
||||||
par = func(fn, _, 'b', _);
|
|
||||||
deepEqual(par(), [undefined, 'b', undefined]);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(4);
|
skipTest(4);
|
||||||
|
|||||||
Reference in New Issue
Block a user