Skip to content

Commit

Permalink
debouncer: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
hbbio committed May 26, 2024
1 parent aa937d8 commit 2bb4fd5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/debouncer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expect, test } from "vitest";

import { debouncer } from "./debouncer";
import { isEqual } from "./isEqual.test";
import { sleep } from "./promise";
import { Sheet } from "./sheet";

test("debouncer", async () => {
const proxy = new Sheet(isEqual).newProxy();
const waiting = proxy.new(false);
const deb = debouncer(20, waiting);
const v = proxy.new(0);
for (let i = 1; i <= 10; i++) {
deb((i) => v.set(i), i);
await sleep(5);
expect(v.consolidatedValue).toBe(0);
}
await sleep(30);
expect(v.consolidatedValue).toBe(10);
});

0 comments on commit 2bb4fd5

Please sign in to comment.