@std/testing
Обзор
Этот пакет предоставляет утилиты для тестирования.
- Тестирование в стиле BDD
- Тестовые двойники (мокирование)
- Имитация времени и таймеров
- Тестирование снимков
- Утверждения типов
import { assertSpyCalls, spy } from "@std/testing/mock";
import { FakeTime } from "@std/testing/time";
function secondInterval(cb: () => void) {
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);
});
Добавьте в проект
›_
deno add jsr:@std/testing
© 2018–2025 the Deno authors
Licensed under the MIT License.
https://docs.deno.com/runtime/reference/std/testing