mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
7eed8d0e04
* BREAKING(testing): remove `TimeError` in favor of built-in error classes * work * refactor: use `Error` instead of `TypeError` * work * fix * work * work * fix * fix |
||
---|---|---|
.. | ||
__snapshots__ | ||
_test_suite.ts | ||
_test_utils.ts | ||
_time.ts | ||
bdd_test.ts | ||
bdd.ts | ||
deno.json | ||
mock_test.ts | ||
mock.ts | ||
README.md | ||
snapshot_test.ts | ||
snapshot.ts | ||
time_test.ts | ||
time.ts | ||
types_test.ts | ||
types.ts |
This package provides utilities for testing.
import { assertSpyCalls, spy } from "@std/testing/mock";
import { FakeTime } from "@std/testing/time";
function secondInterval(cb: () => void): number {
return setInterval(cb, 1000);
}
Deno.test("secondInterval calls callback every second and stops after being cleared", () => {
using time = new FakeTime();
const cb = spy();
const intervalId = secondInterval(cb);
assertSpyCalls(cb, 0);
time.tick(500);
assertSpyCalls(cb, 0);
time.tick(500);
assertSpyCalls(cb, 1);
time.tick(3500);
assertSpyCalls(cb, 4);
clearInterval(intervalId);
time.tick(1000);
assertSpyCalls(cb, 4);
});