How to use the jsdom.jsdom function in jsdom

To help you get started, we’ve selected a few jsdom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jasonphillips / draft-js-richbuttons-plugin / src / __test__ / index.js View on Github external
import React from 'react';
import { mount } from 'enzyme';
import { EditorState, ContentState } from 'draft-js';
import DraftPasteProcessor from 'draft-js/lib/DraftPasteProcessor';
import chai from 'chai';
const expect = chai.expect;

import createRichButtonsPlugin from '../index';
import { MAX_LIST_DEPTH, INLINE_STYLES, BLOCK_TYPES } from '../config/types';

process.env.NODE_ENV = 'test';

const exposedProperties = ['window', 'navigator', 'document'];
const blankEvent = {preventDefault: () => null}

global.document = jsdom('');
global.window = document.defaultView;
Object.keys(document.defaultView).forEach((property) => {
  if (typeof global[property] === 'undefined') {
    exposedProperties.push(property);
    global[property] = document.defaultView[property];
  }
});

// chaiEnzyme needs to be initialised here, so that canUseDOM is set
// to true when react-dom initialises (which chai-enzyme depends upon)
const chaiEnzyme = require('chai-enzyme');
chai.use(chaiEnzyme());

describe('Draft RichButtons Plugin', () => {
  const createEditorStateFromHTML = (html) => {
    const blocks = DraftPasteProcessor.processHTML(html);
github Berkeley-Correctness-Group / DLint / tests / dlint / okay_DocumentFunctionsMisuse12.js View on Github external
\
    \
    \
      <p id="\&quot;para1\&quot;">Some text here</p>\
      <button>blue</button>\
      <button>red</button>\
    \
    \
    ";
    	//Create the document
    	document = jsdom.jsdom(docStr);
    	window = document.defaultView;
    	DOMParser = require('xmldom').DOMParser;
    	alert = function(msg) {}
    	document.adoptNode = function(node) {return node;};
    	document.createCDATASection = function(str) {return {};};
    	document.createNodeIterator = function(a, b, c) {return {};};
    	document.enableStyleSheetsForSet = function (name) {};
    	document.createRange = function() {};
    	document.hasFocus = function() {};
    	document.getSelection = function () {};
    }
    // --- end loading pseudo DOM ---
    // https://developer.mozilla.org/en-US/docs/Web/API/Document/createRange
    var range = document.createRange();
    
    // range.setStart(startNode, startOffset);
github Berkeley-Correctness-Group / DLint / tests / dlint / buggy_DocumentFuctionsMisuse15.js View on Github external
\
    \
    \
      <p id="\&quot;para1\&quot;">Some text here</p>\
      <button>blue</button>\
      <button>red</button>\
    \
    \
    ";
    	//Create the document
    	document = jsdom.jsdom(docStr);
    	window = document.defaultView;
    	DOMParser = require('xmldom').DOMParser;
    	alert = function(msg) {}
    	document.adoptNode = function(node) {return node;};
    	document.createCDATASection = function(str) {return {};};
    	document.createNodeIterator = function(a, b, c) {return {};};
    	document.enableStyleSheetsForSet = function (name) {};
    	document.createRange = function() {};
    	document.hasFocus = function() {};
    	document.getSelection = function () {};
    }
    // --- end loading pseudo DOM ---
    // the first argument should be a string
    var cdata = document.createElement(true);
})();
github uber / react-vis / tests / setup.js View on Github external
/* eslint-disable no-undef */
import jsdom from 'jsdom';

global.document = jsdom.jsdom('');
global.window = document.defaultView;
Object.keys(document.defaultView).forEach(function mapProperties(property) {
  if (typeof global[property] === 'undefined') {
    global[property] = document.defaultView[property];
  }
});

global.navigator = {
  userAgent: 'node.js'
};

/* eslint-enable no-undef */
github eddyerburgh / avoriaz / test / unit / setup / .mocha-webpack-setup.js View on Github external
const chai = require('chai');
const sinon = require('sinon');
const sinonChai = require('sinon-chai');
const jsdom = require('jsdom').jsdom;

global.expect = chai.expect;
global.sinon = sinon;

chai.use(sinonChai);

// Set up JS DOM
const exposedProperties = ['window', 'navigator', 'document'];

global.document = jsdom('<style></style>');
global.window = document.defaultView;

Object.keys(document.defaultView).forEach((property) =&gt; {
  if (typeof global[property] === 'undefined') {
    exposedProperties.push(property);
    global[property] = document.defaultView[property];
  }
});

global.navigator = {
  userAgent: 'node.js'
};

documentRef = document;
github ashiguruma / patternomaly / test / shapes / index.js View on Github external
import { assert } from 'chai';
import * as jsdom from 'jsdom';
import { getRandomShape } from '../../src/shapes/index';
import { shapes, deprecatedShapes } from '../../src/shapes/shapes-list';

global.document = jsdom.jsdom('');

describe('shapes', () =&gt; {
  describe('#getRandomShape', () =&gt; {
    it('should NOT generate the specified excluded shape types', () =&gt; {
      const randomShapes = [];
      const excludedShapes = Object.keys(shapes);
      const removedShape = excludedShapes.splice(0, 1)[0];
      let containsExcludedShape = false;

      for (let i = 0; i &lt; 30; i++) {
        randomShapes.push(getRandomShape(excludedShapes));
      }

      containsExcludedShape = randomShapes.some(shape =&gt; shape !== removedShape);

      assert.isNotOk(containsExcludedShape, 'an excluded shape was generated');
github blackjk3 / react-form-builder / test / dom-mock.js View on Github external
module.exports = function(markup) {
  if (typeof document !== 'undefined') return;
  
  var jsdom = require('jsdom').jsdom;
  
  global.document = jsdom(markup || '');
  global.window = document.parentWindow;

  global.$ = global.jQuery = require('jquery')(global.window);
  global.navigator = {
    userAgent: 'node.js'
  };
};
github freedomofpress / sunder / test / setup.js View on Github external
import 'babel-polyfill';
import { jsdom } from 'jsdom';
import chai from 'chai';
import dirtyChai from 'dirty-chai';

/**
 * jsdom setup
 */
global.document = jsdom('<div id="root"></div>');
global.window = document.defaultView;
global.navigator = global.window.navigator;
window.localStorage = window.sessionStorage = {
  getItem(key) {
    return this[key];
  },
  setItem(key, value) {
    this[key] = value;
  },
  removeItem(key) {
    this[key] = undefined;
  },
};

/**
 * Get rid of those dirty dirty assertions on property access that chai loves
github Automattic / wp-calypso / client / lib / react-test-env-setup / index.js View on Github external
module.exports = function( markup, features ) {
	features = assign( {}, defaultFeatures, features );

	global.document = jsdom( markup, {
		url: 'http://example.com/',
		features: {
			FetchExternalResources: false,
			ProcessExternalResources: false
		}
	} );
	global.window = document.defaultView;
	global.navigator = window.navigator;
	global.Element = window.Element;
	global.history = window.history;

	if ( features.localStorage ) {
		require( 'lib/local-storage' )( global );
	}

	if ( features.XMLHttpRequest ) {
github SkaceKamen / vscode-sqflint / client / fetch-description.js View on Github external
function parseDescription(filepath) {
	let data = { properties: [] };
	let values = data.properties;
	
	let contents = fs.readFileSync(filepath).toString();
	let doc = jsdom(contents, {
		features: { FetchExternalResources: false }
	});

	let tables = doc.getElementsByClassName('bikitable');
	if (tables.length != 1) {
		throw new Error("Failed to find correct .bikitable. Found: " + tables.length + " tables");
	}

	let table = tables[0];
	let rows = table.children[0].children;

	for (var i = 0; i &lt; rows.length; i++) {
		if (i == 0) continue;

		let row = rows[i];
		let name = clearText(row.children[1].textContent);