1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00
denoland-deno/tests/unit_node/timers_test.ts
Asher Gomez 92f6188253
chore: use @std import instead of @test_util/std (#22398)
This PR:
1. Replaces `@test_util/std`-prefixed imports with `@std`.
2. Adds `@std/` import map entries to a few `deno.json` files.
2024-02-13 02:05:10 +00:00

62 lines
1.4 KiB
TypeScript

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assert, fail } from "@std/assert/mod.ts";
import * as timers from "node:timers";
import * as timersPromises from "node:timers/promises";
Deno.test("[node/timers setTimeout]", () => {
{
const { clearTimeout, setTimeout } = timers;
const id = setTimeout(() => {});
clearTimeout(id);
}
{
const id = timers.setTimeout(() => {});
timers.clearTimeout(id);
}
});
Deno.test("[node/timers setInterval]", () => {
{
const { clearInterval, setInterval } = timers;
const id = setInterval(() => {});
clearInterval(id);
}
{
const id = timers.setInterval(() => {});
timers.clearInterval(id);
}
});
Deno.test("[node/timers setImmediate]", () => {
{
const { clearImmediate, setImmediate } = timers;
const id = setImmediate(() => {});
clearImmediate(id);
}
{
const id = timers.setImmediate(() => {});
timers.clearImmediate(id);
}
});
Deno.test("[node/timers/promises setTimeout]", () => {
const { setTimeout } = timersPromises;
const p = setTimeout(0);
assert(p instanceof Promise);
return p;
});
// Regression test for https://github.com/denoland/deno/issues/17981
Deno.test("[node/timers refresh cancelled timer]", () => {
const { setTimeout, clearTimeout } = timers;
const p = setTimeout(() => {
fail();
}, 1);
clearTimeout(p);
p.refresh();
});