std/testing
2024-06-30 08:30:10 +00:00
..
__snapshots__ test(testing): correct test names (#4585) 2024-04-15 16:39:17 +10: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(testing): release testing@1.0.0-rc.1 (#5142) 2024-06-26 07:36:35 +00:00
mock_test.ts fix(testing): correctly throw in constructor with spy() (#5139) 2024-06-26 16:32:08 +09:00
mock.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
README.md docs(testing): add module docs (#5147) 2024-06-26 16:26:28 +10:00
snapshot_test.ts chore: switch to JSR-oriented codebase (#4650) 2024-04-29 11:57:30 +09:00
snapshot.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
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);
});