|
@@ -3,20 +3,20 @@
|
|
|
|
|
|
import { expect } from 'chai';
|
|
|
|
|
|
-import { debounce } from '@jupyterlab/coreutils';
|
|
|
+import { Debouncer } from '@jupyterlab/coreutils';
|
|
|
|
|
|
-describe('debounce()', () => {
|
|
|
- it('should debounce a function within an interval', async () => {
|
|
|
+describe('Debouncer', () => {
|
|
|
+ it('should debounce a function within a limit interval', async () => {
|
|
|
let called = 0;
|
|
|
- const interval = 500;
|
|
|
- const debounced = debounce(async () => {
|
|
|
+ const limit = 500;
|
|
|
+ const debouncer = new Debouncer(async () => {
|
|
|
called += 1;
|
|
|
- }, interval);
|
|
|
- const one = debounced.invoke();
|
|
|
- const two = debounced.invoke();
|
|
|
- const three = debounced.invoke();
|
|
|
- const four = debounced.invoke();
|
|
|
- const five = debounced.invoke();
|
|
|
+ }, limit);
|
|
|
+ const one = debouncer.invoke();
|
|
|
+ const two = debouncer.invoke();
|
|
|
+ const three = debouncer.invoke();
|
|
|
+ const four = debouncer.invoke();
|
|
|
+ const five = debouncer.invoke();
|
|
|
await five;
|
|
|
expect(called).to.equal(1);
|
|
|
await four;
|
|
@@ -27,9 +27,9 @@ describe('debounce()', () => {
|
|
|
expect(called).to.equal(1);
|
|
|
await one;
|
|
|
expect(called).to.equal(1);
|
|
|
- await debounced.invoke();
|
|
|
+ await debouncer.invoke();
|
|
|
expect(called).to.equal(2);
|
|
|
- await debounced.invoke();
|
|
|
+ await debouncer.invoke();
|
|
|
expect(called).to.equal(3);
|
|
|
});
|
|
|
});
|