std/testing
denobot 940568c62d
chore: release 2024.07.02 (#5254)
Co-authored-by: kt3k <kt3k@users.noreply.github.com>
2024-07-02 20:43:42 +09:00
..
__snapshots__ fix(testing): throw error eagerly when insufficient permissions are granted to write to snapshot file in update mode (#5201) 2024-07-01 11:14:37 +09:00
_test_suite.ts docs(testing): improve the docs of @std/testing (#5033) 2024-06-17 11:31:31 +09:00
_test_utils.ts refactor(testing): remove use of public keyword (#5051) 2024-06-17 15:11:31 +12:00
_time.ts chore: update copyright year (#4046) 2024-01-02 08:11:32 +11:00
bdd_test.ts test(testing): improve bdd testing (#5136) 2024-06-25 19:26:12 +09:00
bdd.ts refactor(assert,async,bytes,cli,collections,crypto,csv,data-structures,datetime,dotenv,encoding,expect,fmt,front-matter,fs,html,http,ini,internal,io,json,jsonc,log,media-types,msgpack,net,path,semver,streams,testing,text,toml,ulid,url,uuid,webgpu,yaml): import from @std/assert (#5199) 2024-06-30 08:30:10 +00:00
deno.json chore: release 2024.07.02 (#5254) 2024-07-02 20:43:42 +09:00
mock_test.ts fix(testing): correctly throw in constructor with spy() (#5139) 2024-06-26 16:32:08 +09:00
mock.ts refactor(expect,testing): update @std/assert imports (#5242) 2024-07-02 14:07:46 +10:00
README.md docs(testing): add module docs (#5147) 2024-06-26 16:26:28 +10:00
snapshot_test.ts fix(testing): throw error eagerly when insufficient permissions are granted to write to snapshot file in update mode (#5201) 2024-07-01 11:14:37 +09:00
snapshot.ts refactor(expect,testing): update @std/assert imports (#5242) 2024-07-02 14:07:46 +10:00
time_test.ts test(testing): improve FakeTime testing (#5123) 2024-06-25 15:51:24 +09:00
time.ts refactor(assert,async,bytes,cli,collections,crypto,csv,data-structures,datetime,dotenv,encoding,expect,fmt,front-matter,fs,html,http,ini,internal,io,json,jsonc,log,media-types,msgpack,net,path,semver,streams,testing,text,toml,ulid,url,uuid,webgpu,yaml): import from @std/assert (#5199) 2024-06-30 08:30:10 +00:00
types_test.ts refactor: make the code work under verbatimModuleSyntax (#4406) 2024-02-27 21:57:25 +00:00
types.ts docs(testing): add module docs (#5147) 2024-06-26 16:26:28 +10:00

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