示例工程 30-web-components-types

30-web-components-types/04-observed-attributes/main.test.mjs

javascript · 0.4 KB

运行:30 · observed-attributes

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

import { test } from 'node:test';
import assert from 'node:assert/strict';
 
test('observedAttributes 是静态侧声明,运行时由浏览器读取', async () => {
  globalThis.HTMLElement = class {};
  delete globalThis.customElements;
  const { run, XGreeting } = await import('./dist/main.js');
  assert.throws(() => run(() => {}), /浏览器/);
  assert.deepEqual(XGreeting.observedAttributes, ['name']);
});