# global-jsdom

> Enable DOM in Node.js

Latest version **30.0.0** (published 2026-09-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install global-jsdom
pnpm add global-jsdom
yarn add global-jsdom
bun add global-jsdom
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 30.0.0 |
| Published | 2026-09-04 |
| First published | 2017-10-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22 |
| Dependencies | 0 |
| Unpacked size | 9.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 76 |
| Author | jonathan schatz |
| Maintainers | modosc |
| Keywords | dom, jsdom, test |

## Links

- npm: https://www.npmjs.com/package/global-jsdom
- Repository: https://github.com/modosc/global-jsdom
- Homepage: https://github.com/modosc/global-jsdom#readme
- Issues: https://github.com/modosc/global-jsdom/issues
- npm.io page: https://npm.io/package/global-jsdom

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 30.0.0 (latest) — 2026-09-04
- 29.0.0 — 2026-03-16
- 28.0.0 — 2026-02-02
- 27.0.0 — 2025-09-18
- 26.0.0 — 2025-01-10
- 25.0.0 — 2024-09-17
- 24.0.0 — 2024-01-27
- 9.2.0 — 2023-12-10
- 9.1.0 — 2023-08-06
- 9.0.1 — 2023-05-03
- 9.0.0 — 2023-05-03
- 8.8.0 — 2023-03-20
- 8.7.0 — 2023-01-08
- 8.6.0 — 2022-09-26
- 8.5.0 — 2022-06-24
- … 17 more at https://npm.io/package/global-jsdom/versions

## README

# global-jsdom

[![npm version](http://img.shields.io/npm/v/global-jsdom.svg?style=flat-square)](https://www.npmjs.com/package/global-jsdom)
![Node.js CI](https://github.com/modosc/global-jsdom/workflows/Node.js%20CI/badge.svg?branch=main)

> Enables DOM in Node.js
> `global-jsdom` will inject `document`, `window` and other DOM API into your Node.js environment. This allows you to run browser tests in Node.js. The specific attributes set on `global` come directly from the `jsdom` version you have installed.

## Versioning

`global-jsdom` uses the same major version as the `jsdom` that it wraps.

## Install

Requires [node][] >= 20.

```
npm install --save-dev --save-exact jsdom global-jsdom
```

[node]: https://github.com/nodejs/node
[jsdom]: https://github.com/jsdom/jsdom

## Usage

Just invoke it to turn your Node.js environment into a DOM environment.

```js
// commonjs
require("global-jsdom/register");

// or es2015
import "global-jsdom/register";

// you can now use the DOM
document.body.innerHTML = "hello";

// you can also access the current jsdom instance through $jsdom
global.$jsdom.reconfigure({});
```

## Configuration

You may pass configuration parameters to `jsdom` like so:

```js
// commonjs
const globalJsdom = require("global-jsdom");

// or es2015
import globalJsdom from "global-jsdom";

// then
globalJsdom(html, options);
```

Check the [jsdom.jsdom()][] documentation for valid values for the `options`
parameter.

### Default Options

The following set of default options are passed to `jsdom`

```js
{
  // if url isn't set then localStorage breaks with a cryptic error, see
  // https://github.com/jsdom/jsdom/issues/2304#issuecomment-408320484
  url: 'http://localhost:3000',
  // pretendToBeVisual is enabled so that react works, see
  // https://github.com/jsdom/jsdom#pretending-to-be-a-visual-browser
  pretendToBeVisual: true,
}
```

### Cleanup

To clean up the global namespace just invoke the returned function:

```js
// commonjs
const cleanup = require("global-jsdom")();

// es2015
import globalJsdom from "global-jsdom";
const cleanup = globalJsdom();

// do things, then
cleanup();
```

## Tape

In [tape][], run it before your other tests.

```js
require("global-jsdom/register");

test("your tests", (t) => {
  /* and so on... */
});
```

## Mocha

**Simple:** Use Mocha's `--require` option. Add this to the `test/mocha.opts` file (create it if it doesn't exist)

```
-r global-jsdom/register
```

**Advanced:** For finer control, you can instead add it via [mocha]'s `before` and `after` hooks.

```js
before(function () {
  this.jsdom = require("global-jsdom")();
});

after(function () {
  this.jsdom();
});
```

[tape]: https://github.com/substack/tape
[mocha]: https://mochajs.org/
[jsdom.jsdom()]: https://github.com/tmpvar/jsdom/#for-the-hardcore-jsdomjsdom

## ES2015

If you're using a [recent version of
node](https://nodejs.org/api/esm.html#esm_conditional_exports) then `import` should
just work:

```js
import "global-jsdom/register";
import React from "react";
import jQuery from "jquery";
// ...
```

## Typescript

The library includes automatic support providing the necessary type declarations for an integration without further configuration.

```ts
import globalJsdom from "global-jsdom";

describe("Typescript test example", () => {
  let cleanup: { (): void };

  before(() => {
    cleanup = globalJsdom();
  });

  after(() => {
    cleanup();
  });
});
```

## Thanks

original code forked from [jsdom-global](https://github.com/rstacruz/jsdom-global)

---
_Source: https://npm.io/package/global-jsdom · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
