Skip to content

Files

Latest commit

8d1d2d7 · Aug 16, 2024

History

History
This branch is 587 commits behind denoland/std:main.

testing

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jul 11, 2024
Jun 26, 2024
Jul 11, 2024
Jun 17, 2024
Jul 22, 2024
Jul 9, 2024
Jul 11, 2024
Jul 31, 2024
Jul 30, 2024
Jul 30, 2024
Jul 31, 2024
Jul 11, 2024
Jul 29, 2024
Jul 29, 2024
Aug 16, 2024
Aug 16, 2024

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);
});