示例工程 30-web-components-types

30-web-components-types/01-typed-element/main.test.mjs

javascript · 0.5 KB

运行:30 · typed-element

点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。

import { test } from 'node:test';
import assert from 'node:assert/strict';
 
test('自定义元素在 Node 里不可用,但类型与类本身可测', async () => {
  globalThis.HTMLElement = class {};
  delete globalThis.customElements;
  const { defineCounter, run, XCounter } = await import('./dist/main.js');
  assert.throws(() => run(() => {}), /浏览器/);
  assert.equal(typeof XCounter, 'function');
  assert.throws(() => defineCounter(), /浏览器/);
});