std/testing
Caleb Cox 381d70dcd1
docs(archive,log,testing): correct typos (#5995)
* docs(log,testing): replace colours with colors

Use the American spelling of colors in docs for consistency with module
and option names.

* docs(archive,testing): replace it's with its

* fix

---------

Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
2024-09-16 22:48:56 +00:00
..
__snapshots__ docs(archive,log,testing): correct typos (#5995) 2024-09-16 22:48:56 +00:00
_test_suite.ts refactor(archive,async,cli,csv,dotenv,encoding,expect,fmt,front-matter,fs,http,internal,log,net,path,semver,testing,text,webgpu,yaml): enable "exactOptionalPropertyTypes" option (#5892) 2024-09-04 14:15:01 +09:00
_test_utils.ts refactor(testing): remove use of public keyword (#5051) 2024-06-17 15:11:31 +12:00
_time.ts fix(testing): FakeTime fakes AbortSignal.timeout (#5500) 2024-07-22 13:07:48 +09:00
bdd_test.ts docs(archive,log,testing): correct typos (#5995) 2024-09-16 22:48:56 +00:00
bdd.ts refactor(archive,async,cli,csv,dotenv,encoding,expect,fmt,front-matter,fs,http,internal,log,net,path,semver,testing,text,webgpu,yaml): enable "exactOptionalPropertyTypes" option (#5892) 2024-09-04 14:15:01 +09:00
deno.json chore: release 2024.09.04 (#5908) 2024-09-04 19:37:53 +09:00
mock_test.ts refactor(archive,async,cli,csv,dotenv,encoding,expect,fmt,front-matter,fs,http,internal,log,net,path,semver,testing,text,webgpu,yaml): enable "exactOptionalPropertyTypes" option (#5892) 2024-09-04 14:15:01 +09:00
mock.ts refactor(archive,async,cli,csv,dotenv,encoding,expect,fmt,front-matter,fs,http,internal,log,net,path,semver,testing,text,webgpu,yaml): enable "exactOptionalPropertyTypes" option (#5892) 2024-09-04 14:15:01 +09:00
README.md docs(testing): add module docs (#5147) 2024-06-26 16:26:28 +10:00
snapshot_test.ts docs(archive,log,testing): correct typos (#5995) 2024-09-16 22:48:56 +00:00
snapshot.ts docs(archive,log,testing): correct typos (#5995) 2024-09-16 22:48:56 +00:00
time_test.ts refactor(testing): align additional error messages (#5810) 2024-08-26 14:22:16 +09:00
time.ts refactor(testing): align additional error messages (#5810) 2024-08-26 14:22:16 +09:00
types_test.ts fix(testing): fix IsExact edge cases (#5676) 2024-08-16 20:28:29 +09:00
types.ts fix(testing): fix IsExact edge cases (#5676) 2024-08-16 20:28:29 +09: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);
});