mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Tweak _.throttle unit test and add _.bind test.
Former-commit-id: b863194c661d97177bbcda9676699e9753f0db22
This commit is contained in:
17
test/test.js
17
test/test.js
@@ -209,6 +209,13 @@
|
|||||||
bound(['b'], 'c');
|
bound(['b'], 'c');
|
||||||
deepEqual(args, ['a', ['b'], 'c']);
|
deepEqual(args, ['a', ['b'], 'c']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('ensure `new bound` is an instance of `func`', function() {
|
||||||
|
var func = function() {},
|
||||||
|
bound = _.bind(func, {});
|
||||||
|
|
||||||
|
ok(new bound instanceof func);
|
||||||
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
@@ -1796,8 +1803,9 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('should trigger a trailing call when invoked in a loop', function() {
|
asyncTest('should trigger a trailing call when invoked in a loop', function() {
|
||||||
var counter = 0,
|
var actual,
|
||||||
limit = 90,
|
counter = 0,
|
||||||
|
limit = 80,
|
||||||
throttled = _.throttle(function() { counter++; }, 32),
|
throttled = _.throttle(function() { counter++; }, 32),
|
||||||
start = new Date;
|
start = new Date;
|
||||||
|
|
||||||
@@ -1805,14 +1813,15 @@
|
|||||||
throttled();
|
throttled();
|
||||||
}
|
}
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
|
actual = counter + 2;
|
||||||
throttled();
|
throttled();
|
||||||
throttled();
|
throttled();
|
||||||
}, 64);
|
}, 64);
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
ok(counter > 4);
|
equal(counter, actual);
|
||||||
QUnit.start();
|
QUnit.start();
|
||||||
}, 96);
|
}, 128);
|
||||||
|
|
||||||
ok(counter > 1);
|
ok(counter > 1);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user