Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
abdel-17 committed Jun 11, 2024
1 parent 6b8bc3f commit ed205bf
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/runed/src/lib/utilities/watch/watch.test.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe("watch", () => {
}
);

testWithEffect("lazy watchers correctly pass the initial value as the previous value", () => {
testWithEffect("lazy watchers pass the initial value as the previous value", () => {
return new Promise((resolve) => {
let count = $state(0);

Expand Down Expand Up @@ -100,4 +100,24 @@ describe("watch", () => {
await sleep(0);
expect(runs).toBe(1);
});

testWithEffect("once watchers pass the initial value as the previous value", () => {
return new Promise((resolve) => {
let count = $state(0);

watchOnce(
() => count,
(count, prevCount) => {
expect(count).toBe(1);
expect(prevCount).toBe(0);
resolve();
}
);

// Wait for the watcher's initial run to determine its dependencies.
sleep(0).then(() => {
count = 1;
});
});
});
});

0 comments on commit ed205bf

Please sign in to comment.