ungleich-staticcms/assets/u/static/popper.js-1.16.0/packages/popper/tests/unit/debounce.js
Nico Schottelius 16fb2bb919 import popper.js
Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
2019-12-31 01:21:21 +01:00

32 lines
792 B
JavaScript

import { microtaskDebounce, taskDebounce } from '../../src/utils/debounce';
const microTasksAvailable = window.Promise
describe('utils/debounce', () => {
it('microtaskDebounce: should be called only once', done => {
if (!microTasksAvailable) {
pending();
}
let i = 0;
const debounced = microtaskDebounce(() => i++);
debounced();
debounced();
debounced();
setTimeout(() => {
expect(i).toBe(1, 'debounce is called only once');
done();
}, 1);
});
it('taskDebounce: should be called only once', done => {
let i = 0;
const debounced = taskDebounce(() => i++);
debounced();
debounced();
debounced();
setTimeout(() => {
expect(i).toBe(1, 'debounce is called only once');
done();
}, 1);
});
});