Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
jsdom-sandbox
Advanced tools
Readme
jsdom :heart: the global namespace
document
and window
available globallyThe easiest way is to install jsdom-sandbox
as a devDependency
,
by running
npm install jsdom jsdom-sandbox --save-dev
This package is a thin wrapper around jsdom, taking care of exposing all global DOM properties during the test and cleaning up resources after the completed test.
The sandbox
function takes three parameters and the first two are used to create a new jsdom
instance each time the function is called:
html
, a string
containing html.options
, an object
with options for customizing jsdom
.callback
, the wrapper function. This function has an optional parameter which is the actual jsdom
instance.var dom = require('jsdom-sandbox');
dom.sandbox('<div>foo</div>', { url: 'https://example.com/' }, function (jsdom) {
// do something with the jsdom instance
jsdom.reconfigure({ userAgent: "Mozilla/5.0" });
// use global properties
document.dispatchEvent(new Event("mouseover"));
// the rest of the unit test
// ...
});
For a complete list of options and features, please refer to the jsdom official documentation.
var dom = require('jsdom-sandbox');
var test = require('tape');
test('foo', function (t) {
dom.sandbox('<div id="foo">bar</div>', {}, function () {
t.equal(document.getElementById('foo').innerHTML, 'bar');
t.end();
});
});
import dom from 'jsdom-sandbox';
import test from 'tape';
test('foo', (t) => {
dom.sandbox('<div id="foo">bar</div>', {}, () => {
t.equal(document.getElementById('foo').innerHTML, 'bar');
t.end();
});
});
import * as dom from "jsdom-sandbox";
import * as test from "tape";
test("foo", (t) => {
dom.sandbox("<div id='foo'>bar</div>", {}, () => {
t.equal(document.getElementById("foo").innerHTML, "bar");
t.end();
});
});
Please note that jsdom-sandbox
ships with Typescript typings.
This software is licensed with the MIT license.
© 2017-2018 Monounity, Erik Barke
FAQs
Joining jsdom and the Node.js global environment
The npm package jsdom-sandbox receives a total of 1 weekly downloads. As such, jsdom-sandbox popularity was classified as not popular.
We found that jsdom-sandbox demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.