示例工程 30-web-components-types
30-web-components-types/03-typed-events/main.test.mjs
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
import { test } from 'node:test';
import assert from 'node:assert/strict';
test('自定义元素的事件在 Node 里无法派发,类型与类可测', async () => {
globalThis.HTMLElement = class {};
delete globalThis.customElements;
const { run, XSlider } = await import('./dist/main.js');
assert.throws(() => run(() => {}), /浏览器/);
assert.equal(typeof XSlider, 'function');
});