1 var assert = require('assert');
2 var throttle = require('./');
4 describe('throttle', function(){
13 it('should throttle a function', function(done){
14 var count = counter();
17 var fn = throttle(count, wait);
18 var interval = setInterval(fn, 20);
19 setTimeout(function(){
20 clearInterval(interval);
21 assert(count.invoked === (total / wait));
26 it('should call the function last time', function(done){
27 var count = counter();
29 var fn = throttle(count, wait);
32 assert(count.invoked === 1);
33 setTimeout(function(){
34 assert(count.invoked === 2);
39 it('should pass last context', function(done){
42 var fn = throttle(logctx, wait);
48 setTimeout(function(){
57 it('should pass last arguments', function(done){
60 var fn = throttle(logargs, wait);
63 assert(args && args[0] === 1);
64 setTimeout(function(){
65 assert(args && args[0] === 2);