mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
Add _.callback test.
This commit is contained in:
38
test/test.js
38
test/test.js
@@ -1091,9 +1091,9 @@
|
|||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
function fn() {
|
function fn() {
|
||||||
var args = [this];
|
var result = [this];
|
||||||
push.apply(args, arguments);
|
push.apply(result, arguments);
|
||||||
return args;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
test('should bind a function to an object', 1, function() {
|
test('should bind a function to an object', 1, function() {
|
||||||
@@ -2243,16 +2243,24 @@
|
|||||||
QUnit.module('lodash.callback');
|
QUnit.module('lodash.callback');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
test('should provide arguments to `func`', 1, function() {
|
test('should provide arguments to `func`', 3, function() {
|
||||||
var args,
|
function fn() {
|
||||||
expected = ['a', 'b', 'c', 'd', 'e'];
|
var result = [this];
|
||||||
|
push.apply(result, arguments);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
var callback = _.callback(function() {
|
var callback = _.callback(fn),
|
||||||
args = slice.call(arguments);
|
actual = callback('a', 'b', 'c', 'd', 'e', 'f');
|
||||||
});
|
|
||||||
|
|
||||||
callback.apply(null, expected);
|
ok(actual[0] === null || actual[0] && actual[0].Array);
|
||||||
deepEqual(args, expected);
|
deepEqual(actual.slice(1), ['a', 'b', 'c', 'd', 'e', 'f']);
|
||||||
|
|
||||||
|
var object = {};
|
||||||
|
callback = _.callback(fn, object);
|
||||||
|
actual = callback('a', 'b');
|
||||||
|
|
||||||
|
deepEqual(actual, [object, 'a', 'b']);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should return `_.identity` when `func` is nullish', 2, function() {
|
test('should return `_.identity` when `func` is nullish', 2, function() {
|
||||||
@@ -2865,13 +2873,13 @@
|
|||||||
|
|
||||||
asyncTest('should invoke the `trailing` call with the correct arguments and `this` binding', 2, function() {
|
asyncTest('should invoke the `trailing` call with the correct arguments and `this` binding', 2, function() {
|
||||||
if (!(isRhino && isModularize)) {
|
if (!(isRhino && isModularize)) {
|
||||||
var args,
|
var actual,
|
||||||
count = 0,
|
count = 0,
|
||||||
object = {};
|
object = {};
|
||||||
|
|
||||||
var debounced = _.debounce(function(value) {
|
var debounced = _.debounce(function(value) {
|
||||||
args = [this];
|
actual = [this];
|
||||||
push.apply(args, arguments);
|
push.apply(actual, arguments);
|
||||||
return ++count != 2;
|
return ++count != 2;
|
||||||
}, 32, { 'leading': true, 'maxWait': 64 });
|
}, 32, { 'leading': true, 'maxWait': 64 });
|
||||||
|
|
||||||
@@ -2882,7 +2890,7 @@
|
|||||||
}
|
}
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
strictEqual(count, 2);
|
strictEqual(count, 2);
|
||||||
deepEqual(args, [object, 'a']);
|
deepEqual(actual, [object, 'a']);
|
||||||
QUnit.start();
|
QUnit.start();
|
||||||
}, 64);
|
}, 64);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user