std/testing
2024-11-05 10:16:19 +09:00
..
__snapshots__ docs(archive,log,testing): correct typos (#5995) 2024-09-16 22:48:56 +00:00
_mock_utils.ts feat(testing/unstable): support for stubbing properties (#6128) 2024-10-31 20:54:32 +09:00
_test_suite.ts fix(expect,internal,testing): support expect.assertions (#6032) 2024-10-25 17:29:40 +09:00
_test_utils.ts
_time.ts
bdd_test.ts docs(archive,log,testing): correct typos (#5995) 2024-09-16 22:48:56 +00:00
bdd.ts fix(expect,internal,testing): support expect.assertions (#6032) 2024-10-25 17:29:40 +09:00
deno.json chore: release 2024.11.01 (#6167) 2024-11-01 19:33:15 +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 feat(testing/unstable): support for stubbing properties (#6128) 2024-10-31 20:54:32 +09:00
README.md
snapshot_test.ts docs(archive,log,testing): correct typos (#5995) 2024-09-16 22:48:56 +00:00
snapshot.ts docs(testing): fix typo in snapshot.ts (#6171) 2024-11-05 10:16:19 +09: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
types.ts
unstable_stub_test.ts feat(testing/unstable): support for stubbing properties (#6128) 2024-10-31 20:54:32 +09:00
unstable_stub.ts feat(testing/unstable): support for stubbing properties (#6128) 2024-10-31 20:54:32 +09:00
unstable_types_test.ts feat(testing/unstable): add type test for mutual assignability (#6154) 2024-10-29 20:07:35 +09:00
unstable_types.ts feat(testing/unstable): add type test for mutual assignability (#6154) 2024-10-29 20:07:35 +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);
});