{"id":13500700,"url":"https://github.com/dmatteo/jsdomify","last_synced_at":"2025-04-15T07:07:25.162Z","repository":{"id":28983894,"uuid":"32510452","full_name":"dmatteo/jsdomify","owner":"dmatteo","description":"Create a JSDom instance for browserless testing, exposing some handling methods","archived":false,"fork":false,"pushed_at":"2017-11-15T03:55:03.000Z","size":119,"stargazers_count":78,"open_issues_count":2,"forks_count":9,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-04-15T07:07:19.592Z","etag":null,"topics":["javascript","jsdom","nodejs","testing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dmatteo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-19T08:50:36.000Z","updated_at":"2024-02-13T07:59:42.000Z","dependencies_parsed_at":"2022-09-16T22:41:45.877Z","dependency_job_id":null,"html_url":"https://github.com/dmatteo/jsdomify","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmatteo%2Fjsdomify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmatteo%2Fjsdomify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmatteo%2Fjsdomify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmatteo%2Fjsdomify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmatteo","download_url":"https://codeload.github.com/dmatteo/jsdomify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249023723,"owners_count":21199960,"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":["javascript","jsdom","nodejs","testing"],"created_at":"2024-07-31T22:01:10.524Z","updated_at":"2025-04-15T07:07:25.144Z","avatar_url":"https://github.com/dmatteo.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# jsdomify\n[![Build Status](https://travis-ci.org/dmatteo/jsdomify.svg?branch=master)](https://travis-ci.org/dmatteo/jsdomify)\n[![Coverage Status](https://coveralls.io/repos/github/dmatteo/jsdomify/badge.svg?branch=master)](https://coveralls.io/github/dmatteo/jsdomify?branch=master)\n\nA ready to use DOM right at your finger tips for easy and fast testing without any browser in the Node environment\n(with [mocha](http://mochajs.org/), for example)\n\n**as of jsdom 7.x, jsdomify requires Node v4.x**  \nFor `node 0.1x` compatibility please see [jsdomify-compat](https://github.com/podio/jsdomify-compat)\n\n## Getting started\n\n```\nnpm install --save-dev jsdomify\n```\n\n## Usage\n\nYou can create a new jsdom instance simply with \n\n```javascript\nimport jsdomify from 'jsdomify';\njsdomify.create();\n```\n\nIf you're using ReactJS, you have to be careful of requiring it **after** you've created a DOM instance, like:\n\n```javascript\nimport jsdomify from 'jsdomify';\nlet React;\n\ndescribe('ReactElement', () =\u003e {\n  \n  before(() =\u003e {\n    jsdomify.create();\n    React = require('react');\n  });\n  \n  after(() =\u003e {\n    jsdomify.destroy();\n  });\n  \n  it('should test something', () =\u003e {\n    // your test case  \n  });\n  \n});\n```\n\nYou can even provide an HTML string that will be used as your DOM\n\n```javascript\njsdomify.create(\n  '\u003c!DOCTYPE html\u003e\u003chtml\u003e\u003chead\u003e\u003c/head\u003e\u003cbody\u003ehello\u003c/body\u003e\u003c/html\u003e'\n);\n```\n\n## Methods\n\n`jsdomify` expose some useful methods that can be used to control the DOM instance\n\n### create(domString)\n\n```javascript\njsdomify.create();\n```\n\nCreate a new DOM instance (with or without an optional DOM string).\n\n### clear()\n\n```javascript\njsdomify.clear();\n```\n\nClear the current instance and recreate a new one using the same DOM string (if any).\n\n### destroy()\n\n```javascript\njsdomify.destroy([clearRequireCache]);\n```\n\nClose the window, destroy the document and all the other *leaked* globals.\nCan be used to isolate the tests and prevent leaking from one test suite to another.\n\nIf `clearRequireCache === true` all the cached `node-require` modules will be purged (defaults to `true`).  \nThis is needed in order to use ReactJS with MochaJS and prevent caching issues from one test to another.\n\nRelated issues: \n* [React](https://github.com/facebook/react/issues/4025 \"React issue 4025\")\n* [Mocha](https://github.com/mochajs/mocha/issues/1722 \"Mocha issue 1722\")\n\n\n### getDocument()\n\n```javascript\nconst documentRef = jsdomify.getDocument();\nconst elm = documentRef.getElementById('whatever');\n```\n\nGet a reference to the document that has been created as a `global`.  \nUseful when running with strict linting that doesn't allow globals but you still want to test directly on the document.\n\n## Usage examples\n\nFrom our very own test suite\n\n```javascript\ndescribe('Isolation test', function() {\n\n  before(function() {\n    jsdomify.create();\n  });\n\n  beforeEach(function() {\n    jsdomify.clear();\n  });\n\n  after(function() {\n    jsdomify.destroy();\n  });\n\n  it('should append a child to the body', function() {\n\n    let par = document.createElement(\"P\");\n    const text = document.createTextNode(\"some text\");\n    par.appendChild(text);\n    document.body.appendChild(par);\n    const parCount = document.getElementsByTagName(\"P\");\n\n    expect(document.body.innerHTML, 'not to be empty');\n    expect(parCount.length, 'to be', 1);\n  });\n\n  it('should not find the previously appended child', function() {\n\n    const parCount = document.getElementsByTagName(\"P\");\n\n    expect(document.body.innerHTML, 'to be empty');\n    expect(parCount.length, 'to be', 0);\n  });\n\n});\n```\n\n## Test\n\n```\nnpm test\n```\n\n## License\n\n##### The MIT License (MIT)\n\nCopyright (c) 2015 Domenico Matteo\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmatteo%2Fjsdomify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmatteo%2Fjsdomify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmatteo%2Fjsdomify/lists"}