quickjs-done/tests/test_queue_microtask.js
Sneed Group Holder e18d08e951
Some checks are pending
ci / Linux (Ubuntu) (push) Waiting to run
ci / linux-asan (push) Waiting to run
ci / linux-msan (push) Waiting to run
ci / linux-ubsan (push) Waiting to run
ci / macOS (push) Waiting to run
ci / macos-asan (push) Waiting to run
ci / macos-ubsan (push) Waiting to run
ci / freebsd (push) Waiting to run
ci / qemu-alpine (arm32v6) (push) Waiting to run
ci / qemu-alpine (arm32v7) (push) Waiting to run
ci / qemu-alpine (arm64v8) (push) Waiting to run
ci / qemu-alpine (i386) (push) Waiting to run
ci / qemu-alpine (s390x) (push) Waiting to run
rebase on nextgen
2025-01-06 14:48:15 -06:00

39 lines
1.1 KiB
JavaScript

import { assert, assertArrayEquals, assertThrows } from "./assert.js";
function test_types() {
assertThrows(TypeError, () => queueMicrotask(), "no argument");
assertThrows(TypeError, () => queueMicrotask(undefined), "undefined");
assertThrows(TypeError, () => queueMicrotask(null), "null");
assertThrows(TypeError, () => queueMicrotask(0), "0");
assertThrows(TypeError, () => queueMicrotask({ handleEvent() { } }), "an event handler object");
assertThrows(TypeError, () => queueMicrotask("window.x = 5;"), "a string");
}
function test_async() {
let called = false;
queueMicrotask(() => {
called = true;
});
assert(!called);
}
function test_arguments() {
queueMicrotask(function () { // note: intentionally not an arrow function
assert(arguments.length === 0);
}, "x", "y");
};
function test_async_order() {
const happenings = [];
Promise.resolve().then(() => happenings.push("a"));
queueMicrotask(() => happenings.push("b"));
Promise.reject().catch(() => happenings.push("c"));
queueMicrotask(() => {
assertArrayEquals(happenings, ["a", "b", "c"]);
});
}
test_types();
test_async();
test_arguments();
test_async_order();