Test migration to jest by hand
Apparently using regular expressions is way easier.
This commit is contained in:
21
test/throttle/throttle.js
Normal file
21
test/throttle/throttle.js
Normal file
@ -0,0 +1,21 @@
|
||||
const throttle = (fn, wait) => {
|
||||
let inThrottle, lastFn, lastTime;
|
||||
return function() {
|
||||
const context = this,
|
||||
args = arguments;
|
||||
if (!inThrottle) {
|
||||
fn.apply(context, args);
|
||||
lastTime = Date.now();
|
||||
inThrottle = true;
|
||||
} else {
|
||||
clearTimeout(lastFn);
|
||||
lastFn = setTimeout(function() {
|
||||
if (Date.now() - lastTime >= wait) {
|
||||
fn.apply(context, args);
|
||||
lastTime = Date.now();
|
||||
}
|
||||
}, wait - (Date.now() - lastTime));
|
||||
}
|
||||
};
|
||||
};
|
||||
module.exports = throttle;
|
||||
10
test/throttle/throttle.test.js
Normal file
10
test/throttle/throttle.test.js
Normal file
@ -0,0 +1,10 @@
|
||||
const expect = require('expect');
|
||||
const throttle = require('./throttle.js');
|
||||
|
||||
|
||||
test('throttle is a Function', () => {
|
||||
expect(throttle).toBeInstanceOf(Function);
|
||||
});
|
||||
t.pass('Tested by @chalarangelo on 16/02/2018');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user