{"id":13548670,"url":"https://github.com/rstacruz/jsdom-global","last_synced_at":"2025-05-15T13:07:04.229Z","repository":{"id":45516292,"uuid":"49398694","full_name":"rstacruz/jsdom-global","owner":"rstacruz","description":"Enable DOM in Node.js","archived":false,"fork":false,"pushed_at":"2020-06-19T23:07:53.000Z","size":39,"stargazers_count":478,"open_issues_count":31,"forks_count":38,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-07T20:03:52.586Z","etag":null,"topics":["dom","jsdom","mocha","tape"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rstacruz.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-11T03:05:41.000Z","updated_at":"2025-05-07T08:32:26.000Z","dependencies_parsed_at":"2022-08-12T11:52:15.632Z","dependency_job_id":null,"html_url":"https://github.com/rstacruz/jsdom-global","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstacruz%2Fjsdom-global","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstacruz%2Fjsdom-global/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstacruz%2Fjsdom-global/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstacruz%2Fjsdom-global/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rstacruz","download_url":"https://codeload.github.com/rstacruz/jsdom-global/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253324483,"owners_count":21890854,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dom","jsdom","mocha","tape"],"created_at":"2024-08-01T12:01:13.077Z","updated_at":"2025-05-15T13:07:04.210Z","avatar_url":"https://github.com/rstacruz.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# jsdom-global\n\n\u003e Enables DOM in Node.js\n\njsdom-global will inject `document`, `window` and other DOM API into your Node.js environment. Useful for running, in Node.js, tests that are made for browsers.\n\n[![Status](https://travis-ci.org/rstacruz/jsdom-global.svg?branch=master)](https://travis-ci.org/rstacruz/jsdom-global \"See test builds\")\n\n## Install\n\nRequires [jsdom][].\n\n```\nnpm install --save-dev --save-exact jsdom jsdom-global\n```\n\n[jsdom]: https://github.com/tmpvar/jsdom\n\n## Note\n\njsdom-global now requires jsdom v10 or above. If you need jsdom v9 and below, use the previous version (`jsdom-global@2`).\n\n## Usage\n\nJust invoke it to turn your Node.js environment into a DOM environment.\n\n```js\nrequire('jsdom-global')()\n\n// you can now use the DOM\ndocument.body.innerHTML = 'hello'\n```\n\nYou may also pass parameters to jsdomGlobal() like so: `require('jsdom-global')(html, options)`.\nCheck the [jsdom.jsdom()][] documentation for valid values for the `options` parameter.\n\nTo clean up after itself, just invoke the function it returns.\n\n```js\nvar cleanup = require('jsdom-global')()\n\n// do things\n\ncleanup()\n```\n\n## Tape\n\nIn [tape][], run it before your other tests.\n\n```js\nrequire('jsdom-global')()\n\ntest('your tests', (t) =\u003e {\n  /* and so on... */\n})\n```\n\n## Mocha\n\n__Simple:__ Use Mocha's `--require` option. Add this to the `test/mocha.opts` file (create it if it doesn't exist)\n\n```\n-r jsdom-global/register\n```\n\n__Advanced:__ For finer control, you can instead add it via [mocha]'s `before` and `after` hooks.\n\n```js\nbefore(function () {\n  this.jsdom = require('jsdom-global')()\n})\n\nafter(function () {\n  this.jsdom()\n})\n```\n\n[tape]: https://github.com/substack/tape\n[mocha]: https://mochajs.org/\n[jsdom.jsdom()]: https://github.com/tmpvar/jsdom/#for-the-hardcore-jsdomjsdom\n\n## ES2015\n\nIf you prefer to use `import` rather than `require`, you might want to use `jsdom-global/register` instead. Place it on top of your other import calls.\n\n```js\nimport 'jsdom-global/register'\nimport React from 'react'\nimport jQuery from 'jquery'\n// ...\n```\n\n## Browserify\n\nIf you use [Browserify] on your tests (eg: [smokestack], [tape-run], [budo], [hihat], [zuul], and so on), doing `require('jsdom-global')()` is a noop. In practice, this means you can use jsdom-global even if your tests are powered by browserify, and your test will now work in both the browser and Node.\n\n[zuul]: https://www.npmjs.com/package/zuul\n[tape-run]: https://www.npmjs.com/package/tape-run\n[budo]: https://github.com/mattdesl/budo\n[hihat]: https://www.npmjs.com/package/hihat\n[smokestack]: https://www.npmjs.com/package/smokestack\n\n* Writing your tests (`test.js`):\n\n  ```js\n  require('jsdom-global')()\n\n  // ...do your tests here\n  ```\n\n* Running it with [smokestack]:\n\n  ```sh\n  browserify test.js | smokestack          # run in a browser\n  node test.js                             # or the console\n  browserify test.js --no-bundle-external  # also works (but why bother?)\n  ```\n\n* Running it with Babel ([babelify] or [babel-cli]):\n\n  ```sh\n  browserify test.js -t babelify | smokestack  # run in a browser (with babel)\n  babel-node test.js                           # or the console\n  ```\n\n[Browserify]: http://browserify.org/\n[babel-cli]: https://babeljs.io/docs/usage/cli/\n[babelify]: https://github.com/babel/babelify\n\n## Thanks\n\n**jsdom-global** © 2016+, Rico Sta. Cruz. Released under the [MIT] License.\u003cbr\u003e\nAuthored and maintained by Rico Sta. Cruz with help from contributors ([list][contributors]).\n\n\u003e [ricostacruz.com](http://ricostacruz.com) \u0026nbsp;\u0026middot;\u0026nbsp;\n\u003e GitHub [@rstacruz](https://github.com/rstacruz) \u0026nbsp;\u0026middot;\u0026nbsp;\n\u003e Twitter [@rstacruz](https://twitter.com/rstacruz)\n\n[MIT]: http://mit-license.org/\n[contributors]: http://github.com/rstacruz/jsdom-global/contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frstacruz%2Fjsdom-global","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frstacruz%2Fjsdom-global","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frstacruz%2Fjsdom-global/lists"}