
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
jsdomify-compat
Advanced tools
Create a JSDom instance for browserless testing (node 0.1x compatible)
A ready to use DOM instance right at your finger tips for easy and fast testing without any browser in node.js environment (with mocha, for example)
This is the compatibility version of jsdomify which can run in node.js version 0.10 and 0.12, using JSDOM version 3.1.2
npm install --save-dev jsdomify-compat
You can create a new jsdom instance simply with
var jsdomify = require('jsdomify-compat').create();
Or you can provide a valid HTML string that will be used as your DOM
var jsdomify = require('jsdomify').create(
'<!DOCTYPE html><html><head></head><body>hello</body></html>'
);
jsdomify
expose some useful methods that can be used to control the DOM instance
jsdomify.create();
Create a new DOM instance (with or without the optional DOM string).
jsdomify.clear();
Clear the current instance and recreate a new one using the same DOM string (basically clearing up the DOM).
jsdomify.destroy([clearRequireCache]);
Close the window and destroy the document. Can be used to isolate the tests and prevent leaking from one test suite to another.
If clearRequireCache === true
all the cached node require modules will be purged (defaults to true
).
This is needed in order to use ReactJS with MochaJS.
Related issues:
var documentRef = jsdomify.getDocument();
var elm = documentRef.getElementById('whatever');
Get a reference to the document that has been created as a global
.
Useful when running with strict linting that doesn't allow globals but still want to test things on the document itself.
From our very own test suite
describe('Isolation test', function() {
before(function() {
jsdomify.create();
});
beforeEach(function() {
jsdomify.clear();
});
after(function() {
jsdomify.destroy();
});
it('should append a child to the body', function() {
var par = document.createElement("P");
var text = document.createTextNode("some text");
par.appendChild(text);
document.body.appendChild(par);
var parCount = document.getElementsByTagName("P");
expect(document.body.innerHTML, 'not to be empty');
expect(parCount.length, 'to be', 1);
});
it('should not find the previously appended child', function() {
var parCount = document.getElementsByTagName("P");
expect(document.body.innerHTML, 'to be empty');
expect(parCount.length, 'to be', 0);
});
});
npm test
MIT
FAQs
Create a JSDom instance for browserless testing (node 0.1x compatible)
The npm package jsdomify-compat receives a total of 0 weekly downloads. As such, jsdomify-compat popularity was classified as not popular.
We found that jsdomify-compat demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.