deno.land / std@0.166.0 / testing / mock_examples / interval_test.ts

interval_test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.import { assertSpyCalls, spy } from "../mock.ts";import { FakeTime } from "../time.ts";import { secondInterval } from "./interval.ts";
Deno.test("secondInterval calls callback every second and stops after being cleared", () => { const time = new FakeTime(); const cb = spy();
try { 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); } finally { time.restore(); }});
std

Version Info

Tagged at
a year ago