-
-
Notifications
You must be signed in to change notification settings - Fork 213
Global Registrator
David Ortner edited this page Apr 4, 2024
·
3 revisions
@happy-dom/global-registrator is a utility that registers Happy DOM globally, which makes it easy to setup your own test environment.
npm install @happy-dom/global-registrator --save-dev
Calling GlobalRegistrator.register()
creates a Window instance and applies the properties of the Window instance to the global scope.
import { GlobalRegistrator } from '@happy-dom/global-registrator';
GlobalRegistrator.register({ url: 'http://localhost:3000', width: 1920, height: 1080 });
document.body.innerHTML = `<button>My button</button>`;
const button = document.querySelector('button');
// Outputs: "My button"
console.log(button.innerText);
Calling GlobalRegistrator.unregister()
closes/destroyes the Window instance and restores properties to the same values as they where before calling GlobalRegistrator.register()
.
import { GlobalRegistrator } from '@happy-dom/global-registrator';
GlobalRegistrator.register();
await GlobalRegistrator.unregister();
// Outputs: "undefined"
console.log(global.document);
Help Packages