@native-dom/register
v0.0.10
Published
Global DOM installer for native-dom.
Downloads
118
Readme
@native-dom/register
Manual global installer for native-dom.
Use this package when a test runner or script needs DOM globals but does not use the Vitest or Jest environment packages.
Usage
import { register, unregister } from "@native-dom/register";
const window = register();
try {
document.body.innerHTML = "<button>Save</button>";
document.querySelector("button")?.dispatchEvent(new window.Event("click"));
} finally {
unregister();
}Behavior
register() creates a new Window and installs common DOM globals onto globalThis, including:
window,document,self,location,history,navigator,screen.- DOM constructors such as
Node,Element,HTMLElement,Document,Text,Comment, andDocumentFragment. - Event constructors and
EventTarget. - Observer, CSS, storage, selection, range, form, and collection globals.
- Timer and animation-frame functions bound to the created window.
unregister() restores values that existed before registration and removes globals that were created by this package.
Development
pnpm --filter @native-dom/register build
pnpm --filter @native-dom/register typecheck
pnpm --filter @native-dom/register testPrefer @native-dom/vitest or @native-dom/jest-environment when the test runner can own setup and teardown.
