node/test/parallel/test-timers-promises-scheduler.js
Antoine du Hamel ef6b8cc3c3
test: ensure assertions are reached on more tests
PR-URL: https://github.com/nodejs/node/pull/60728
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2025-11-17 17:10:24 +00:00

52 lines
1.2 KiB
JavaScript

'use strict';
const common = require('../common');
const { scheduler } = require('timers/promises');
const { setTimeout } = require('timers');
const assert = require('assert');
async function testYield() {
await scheduler.yield();
process.emit('foo');
}
testYield().then(common.mustCall());
queueMicrotask(common.mustCall(() => {
process.addListener('foo', common.mustCall());
}));
async function testWait() {
let value = 0;
setTimeout(() => value++, 10);
await scheduler.wait(15);
assert.strictEqual(value, 1);
}
testWait().then(common.mustCall());
async function testCancelableWait1() {
const ac = new AbortController();
const wait = scheduler.wait(1e6, { signal: ac.signal });
ac.abort();
await assert.rejects(wait, {
code: 'ABORT_ERR',
message: 'The operation was aborted',
});
}
testCancelableWait1().then(common.mustCall());
async function testCancelableWait2() {
const wait = scheduler.wait(10000, { signal: AbortSignal.abort() });
await assert.rejects(wait, {
code: 'ABORT_ERR',
message: 'The operation was aborted',
});
}
testCancelableWait2().then(common.mustCall());
assert.throws(() => new scheduler.constructor(), {
code: 'ERR_ILLEGAL_CONSTRUCTOR',
});