Testdom helps you write tests for the browser & node

Usage no npm install needed!

<script type="module">
  import testdom from 'https://cdn.skypack.dev/testdom';



Testdom is a jsdom wrapper to help developers write test code that works both in the browser and in node.

It works by checking if a global document exists in it's current environment. If it does it bails out and expects the browser to provide all available browser globals. If a global document does not exists, it will create one using jsdom.

WANTED! PRs with more tested additional globals.


npm install testdom



Additional globals

Testdom supports an argument of additional globals that will be loaded (using require) only if no DOM exists. This way users can experiment with different modules as browser global replacements and polyfills.

require('testdom')('<html><body></body></html>', {
    localStorage : 'localStorage',

In the additional globals object the key is the name of the global the the value is the module name to be require'd.

Since v1.1.0 we also support arbitrary globals, so anything passed to additional globals that is not a string, we be added globally as is.

Confirmed modules

A list of modules confirmed to work well as a global/polyfill for jsdom.

Global Module Notes
localStorage localStorage 404 link but npm install works
Promise es6-promises Different than es6-promise (singular).


Testling uses browserify to create a browser compatible bundle of your javascripts. Unfortunately jsdom is not compatible with browserify, so we have to tell testling to ignore it.

In your package.json add a browser field and add tell browserify to ignore jsdom.

$ vi package.json

"browser" : {
    "jsdom" : false

Since testdom only tries to require jsdom if no document exists; the browser will never reach that code and we are good. The tests will use the browser's DOM.



  • Upgraded jsdom to 13.0.0 -- requires node 8+


  • Upgraded jsdom to 6.5.1 -- requires node 4+


  • Support for arbitrary globals


  • Upgraded jsdom dependency from 2.x.x to 3.x.x


  • Removed non-jsdom dependencies (& globals)
  • Added ability to require non-jsdom modules only if DOM does not exists
  • Started list of working globals & polyfills


  • Pre changelog era. Who knows what went on.