document and location.
Install
@happy-dom/global-registrator.
terminal
This module exports a “registrator” that injects the mocked browser APIs into the global scope.
This file needs to run before any of your test files. That’s a job for Bun’s built-in preload option. Create a
bunfig.toml file in the root of your project (if it doesn’t already exist) and add the following lines.
The ./happydom.ts file should contain the registration code from the previous step.
bunfig.toml
Now
bun test executes happydom.ts before your test files, so you can write tests that use browser APIs.
With Happy DOM registered, the test passes.
terminal
See the Happy DOM repo and DOM testing.