Experimental Web Worker API implementation for JSDOM.
Last updated 2 months ago by developit .
MIT · Original npm · Tarball · package.json
$ cnpm install jsdom-worker 
SYNC missed versions from official npm registry.


Lets you use Web Workers in Jest!

This is an experimental implementation of the Web Worker API (specifically Dedicated Worker) for JSDOM.

It does not currently do any real threading, rather it implements the Worker interface but all work is done in the current thread. jsdom-worker runs wherever JSDOM runs, and does not require Node.

It supports both "inline" (created via Blob) and standard (loaded via URL) workers.

Hot Take: this module likely works in the browser, where it could act as a simple inline worker "poorlyfill".

npm travis


Jest uses a JSDOM environment by default, which means it doesn't support Workers. This means it is impossible to test code that requires both NodeJS functionality and Web Workers. jsdom-worker implements enough of the Worker spec that it is now possible to do so.


npm i jsdom-worker


import 'jsdom-global/register'
import 'jsdom-worker'

let code = `onmessage = e => postMessage(e.data*2)`
let worker = new Worker(URL.createObjectURL(new Blob([code])))
worker.onmessage = console.log
worker.postMessage(5)  // 10

Usage with Jest

For single tests, simply add import 'jsdom-worker' to your module.

Otherwise, add it via the setupFiles Jest config option:

  "setupFiles": [


MIT License

Current Tags

  • 0.2.1                                ...           latest (2 months ago)

3 Versions

  • 0.2.1                                ...           2 months ago
  • 0.2.0                                ...           2 months ago
  • 0.1.0                                ...           3 years ago
Maintainers (1)
Today 0
This Week 5
This Month 8
Last Day 1
Last Week 3
Last Month 40
Dependencies (2)
Dev Dependencies (7)

Copyright 2014 - 2016 © taobao.org |