New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jsdomify

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsdomify - npm Package Compare versions

Comparing version 0.6.1 to 1.0.0

11

lib/jsdomify.js
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _jsdom = require('jsdom');

@@ -12,3 +16,3 @@

global.document = (0, _jsdom.jsdom)(actualDOM);
global.window = document.parentWindow;
global.window = document.defaultView;
global.location = window.location;

@@ -62,3 +66,3 @@ global.Element = window.Element;

module.exports = {
exports['default'] = {
create: create,

@@ -68,2 +72,3 @@ clear: clear,

getDocument: getDocument
};
};
module.exports = exports['default'];

@@ -41,3 +41,3 @@ /*

// to retrieve a list of classes.
var classes = el.className.replace(/^\s+|\s+$/g, "").split(/\s+/);
var classes = el.className.replace(/^\s+|\s+$/g, '').split(/\s+/);
for (var i = 0; i < classes.length; i++) {

@@ -69,3 +69,3 @@ push.call(this, classes[i]);

toString: function toString() {
return join.call(this, " ");
return join.call(this, ' ');
},

@@ -95,5 +95,5 @@ toggle: function toggle(token) {

defineElementGetter(window.Element.prototype, "classList", function () {
defineElementGetter(window.Element.prototype, 'classList', function () {
return new DOMTokenList(this);
});
};
{
"name": "jsdomify",
"version": "0.6.1",
"version": "1.0.0",
"description": "Create a JSDom instance for browserless testing, exposing some handling methods",

@@ -10,10 +10,10 @@ "main": "lib/jsdomify.js",

"dependencies": {
"jsdom": "3.1.2"
"jsdom": "7.0.0"
},
"devDependencies": {
"babel": "5.6.23",
"coveralls": "2.11.2",
"istanbul": "0.3.17",
"mocha": "2.2.5",
"unexpected": "9.2.1"
"babel": "5.8.29",
"coveralls": "2.11.4",
"istanbul": "0.4.0",
"mocha": "2.3.3",
"unexpected": "10.0.2"
},

@@ -20,0 +20,0 @@ "scripts": {

@@ -8,6 +8,9 @@ # jsdomify

**as of jsdom 7.x, jsdomify requires Node v4.x**
For `node 0.1x` compatibility please see [jsdomify-compat](https://github.com/podio/jsdomify-compat)
## Getting started
```
npm install jsdomify
npm install --save-dev jsdomify
```

@@ -20,9 +23,34 @@

```javascript
var jsdomify = require('jsdomify').create();
import jsdomify from 'jsdomify';
jsdomify.create();
```
Or you can provide a valid HTML string that will be used as your DOM
If you're using ReactJS, you have to be careful of requiring it **after** you've created a DOM instance, like:
```javascript
var jsdomify = require('jsdomify').create(
import jsdomify from 'jsdomify';
let React;
describe('ReactElement', () => {
before(() => {
jsdomify.create();
React = require('react');
});
after(() => {
jsdomify.destroy();
});
it('should test something', () => {
// your test case
});
});
```
You can even provide an HTML string that will be used as your DOM
```javascript
jsdomify.create(
'<!DOCTYPE html><html><head></head><body>hello</body></html>'

@@ -42,3 +70,3 @@ );

Create a new DOM instance (with or withouth the optional DOM string).
Create a new DOM instance (with or without an optional DOM string).

@@ -51,3 +79,3 @@ ### clear()

Clear the current instance and recreate a new one using the same DOM string (basically clearing up the DOM).
Clear the current instance and recreate a new one using the same DOM string (if any).

@@ -60,7 +88,7 @@ ### destroy()

Close the window and destroy the document.
Close the window, destroy the document and all the other *leaked* globals.
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.
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 and prevent caching issues from one test to another.

@@ -75,8 +103,8 @@ Related issues:

```javascript
var documentRef = jsdomify.getDocument();
var elm = documentRef.getElementById('whatever');
const documentRef = jsdomify.getDocument();
const 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.
Useful when running with strict linting that doesn't allow globals but you still want to test directly on the document.

@@ -104,7 +132,7 @@ ## Usage examples

var par = document.createElement("P");
var text = document.createTextNode("some text");
let par = document.createElement("P");
const text = document.createTextNode("some text");
par.appendChild(text);
document.body.appendChild(par);
var parCount = document.getElementsByTagName("P");
const parCount = document.getElementsByTagName("P");

@@ -117,3 +145,3 @@ expect(document.body.innerHTML, 'not to be empty');

var parCount = document.getElementsByTagName("P");
const parCount = document.getElementsByTagName("P");

@@ -134,2 +162,23 @@ expect(document.body.innerHTML, 'to be empty');

## License
MIT
##### The MIT License (MIT)
Copyright (c) 2015 Podio Dev Team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc