Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert.strictEqual(dom.window.document.characterSet, nameWhenOverridden);
assert.strictEqual(dom.window.document.contentType, "text/html"); // encoding should be stripped
if (bodyWhenOverridden) {
assert.strictEqual(dom.window.document.body.textContent, bodyWhenOverridden);
}
});
});
}
});
}
});
});
describe("fromFile", { skipIfBrowser: true }, () => {
for (const encodingFixture of Object.keys(encodingFixtures)) {
const { name, body } = encodingFixtures[encodingFixture];
it(`should sniff ${encodingFixture} as ${name}`, () => {
return JSDOM.fromFile(fixturePath(encodingFixture)).then(dom => {
assert.strictEqual(dom.window.document.characterSet, name);
assert.strictEqual(dom.window.document.body.textContent, body);
});
});
}
});
describe("fromURL", { skipIfBrowser: true }, () => {
let server;
let host;
before(() => {
for (const globalName of jsGlobals) {
assertAliasedGlobal(dom.window, globalName);
}
});
for (const optionValue of ["outside-only", "dangerously"]) {
it(`should include fresh globals when set to "${optionValue}"`, () => {
const dom = new JSDOM(undefined, { runScripts: optionValue });
for (const globalName of jsGlobals) {
assertFreshGlobal(dom.window, globalName);
}
});
}
});
describe("event handlers", () => {
for (const optionValue of [undefined, "outside-only"]) {
describe(`when set to ${formatOptionValue(optionValue)}`, () => {
function createJSDOM() {
return new JSDOM(`<div>`, { runScripts: optionValue });
}
function createJSDOMWithParsedHandlers() {
return new JSDOM(
`
<div></div>`,
{ runScripts: optionValue, url: "https://example.com/" } // url set for hashchange tests
);
}
describe("body onload handler set during parsing", () => {
it("should not evaluate the handler (GH-1848)", () => {
const dom = createJSDOMWithParsedHandlers();</div>
const { JSDOM } = require("../../..");
const xpath = require('../../../lib/jsdom/level3/xpath')((new JSDOM()).window);
const domTestHelper = require('../files/DOMTestCase');
function all1(re, s) {
var l = [];
while (s.length) {
var m = re.exec(s);
if (!m) break;
l.push(m[1]);
s = s.substr(m[0].length);
}
return l;
}
describe("xpath", { skipIfBrowser: true }, () => {
specify("testTokenizeRegexp", function() {
var re = xpath.Stream.prototype.re;
assert.deepEqual(['8', 'a'], all1(re, '8a'));
assert.deepEqual(['8', 'a'], all1(re, ' 8a'));
assert.deepEqual(['fun'], all1(re, 'fun'));
assert.deepEqual(['hi', '+', '3'], all1(re, 'hi+3'));
assert.deepEqual(['fun', '(', ')'], all1(re, 'fun()'));
assert.deepEqual(['..', '/', 'a', '//', 'b'], all1(re, '../a//b'));
assert.deepEqual(['1', '<=', '2', '<', '3', '>=', '4', '=', '5', '!=', '6'], all1(re, '1<=2<3>=4=5!=6'));
assert.deepEqual(['<', '='], all1(re, '< ='));
assert.deepEqual(['a','::','b'], all1(re, 'a::b'));
assert.deepEqual(['a','::','b'], all1(re, 'a :: b'));
assert.deepEqual(['a:b'], all1(re, 'a:b'));
assert.deepEqual(['a'], all1(re, 'a : b')); // can't tokenize : alone
assert.deepEqual(['a:b', '::', 'c'], all1(re, 'a:b::c'));
assert.deepEqual(['a', '::', 'b:c'], all1(re, 'a::b:c'));
"use strict";
const { assert } = require("chai");
const { describe, specify } = require("mocha-sugar-free");
const { JSDOM } = require("../..");
// Tests for MessageEvent
// Spec: https://html.spec.whatwg.org/multipage/comms.html#messageevent
describe("location", () => {
specify("MessageEvent has a read-only property 'type'", () => {
const { window } = new JSDOM();
const event = new window.MessageEvent("fake type");
assert.equal(event.type, "fake type");
assert.throws(() => {
event.type = "oh no";
});
});
specify("MessageEvent has a read-only property 'data'", () => {
const { window } = new JSDOM();
const event = new window.MessageEvent("fake type", {
data: "fake data"
});
'use strict'
require('babel-core/register')
require('babel-polyfill')
const describe = require('mocha-sugar-free').describe
const it = require('mocha-sugar-free').it
const expect = require('chai').expect
const reducer = require('../src/reducers').default
const { audioPlay, audioPlaying, audioPause, audioPaused, audioEnded,
audioRegister, audioUnregister, audioSrc, audioCommand } = require('../src/actions')
const Map = require('immutable').Map
describe('reducers', () => {
describe('AUDIO_REGISTER actions', () => {
it('registers a new id with the state', () => {
const result = reducer(undefined, audioRegister('id'))
expect(result.has('id')).to.be.true
expect(result.get('id').equals(Map({command: 'none', state: 'none', src: ''})))
})
})
describe('AUDIO_UNREGISTER actions', () => {
it('unregisters an id with the state', () => {
const result = reducer(Map({id: 'hello'}), audioUnregister('id'))
expect(result.has('id')).to.be.false
})
})
describe('AUDIO_PLAY actions', () => {
});
it("should canonicalize referrer URLs", () => {
const { document } = (new JSDOM(``, { referrer: "http:example.com" })).window;
assert.strictEqual(document.referrer, "http://example.com/");
});
it("should have a default referrer URL of the empty string", () => {
const { document } = (new JSDOM()).window;
assert.strictEqual(document.referrer, "");
});
});
describe("url", () => {
it("should allow customizing document URL via the url option", () => {
const { window } = new JSDOM(``, { url: "http://example.com/" });
assert.strictEqual(window.location.href, "http://example.com/");
assert.strictEqual(window.document.URL, "http://example.com/");
assert.strictEqual(window.document.documentURI, "http://example.com/");
});
it("should throw an error when passing an invalid absolute URL for url", () => {
assert.throws(() => new JSDOM(``, { url: "asdf" }), TypeError);
assert.throws(() => new JSDOM(``, { url: "/" }), TypeError);
});
it("should canonicalize document URLs", () => {
const { window } = new JSDOM(``, { url: "http:example.com" });
dom.reconfigure({ });
assert.strictEqual(dom.window.top, dom.window);
});
it("should change window.top to undefined if passing undefined", () => {
const dom = new JSDOM();
dom.reconfigure({ windowTop: undefined });
assert.strictEqual(dom.window.top, undefined);
});
});
describe("url", () => {
it("should successfully change the URL", () => {
const dom = new JSDOM(``, { url: "http://example.com/" });
const { window } = dom;
assert.strictEqual(window.document.URL, "http://example.com/");
function testPass(urlString, expected = urlString) {
dom.reconfigure({ url: urlString });
assert.strictEqual(window.location.href, expected);
assert.strictEqual(window.document.URL, expected);
assert.strictEqual(window.document.documentURI, expected);
}
testPass("http://localhost", "http://localhost/");
testPass("http://www.localhost", "http://www.localhost/");
describe("inferring options from the response", () => {
describe("url", () => {
it("should use the URL fetched for a 200", () => {
const url = simpleServer(200, { "Content-Type": "text/html" });
return JSDOM.fromURL(url).then(dom => {
assert.strictEqual(dom.window.document.URL, url);
});
});
it("should preserve full request URL", () => {
const url = simpleServer(200, { "Content-Type": "text/html" });
const path = "t";
const search = "?a=1";
const fragment = "#fragment";
const fullURL = url + path + search + fragment;
return JSDOM.fromURL(fullURL).then(dom => {
"use strict";
const { assert } = require("chai");
const { describe, specify } = require("mocha-sugar-free");
const { JSDOM } = require("../..");
const nonInheritedTags = [
"article", "section", "nav", "aside", "hgroup", "header", "footer", "address", "dt",
"dd", "figure", "figcaption", "main", "em", "strong", "small", "s", "cite", "abbr",
"code", "i", "b", "u"
];
describe("htmlelement", () => {
specify("unknown elements should return HTMLUnknownElement", () => {
const doc = (new JSDOM()).window.document;
const el = doc.createElement("foobar");
assert.ok(
el.constructor === doc.defaultView.HTMLUnknownElement,
"unknown element should inherit from HTMLUnknownElement (createElement)"
);
assert.ok(
el instanceof doc.defaultView.HTMLElement,
"unknown element should inherit from HTMLElement too (createElement)"
);
const doc2 = (new JSDOM("")).window.document;
const el2 = doc2.body.firstChild;
assert.ok(
"use strict";
const { assert } = require("chai");
const { describe, specify } = require("mocha-sugar-free");
const { JSDOM } = require("../..");
describe("location", () => {
specify("window.location and document.location should be equal", () => {
const { window } = new JSDOM();
assert.strictEqual(window.document.location, window.location);
});
specify("window.location.href for a default window is about:blank", () => {
const { window } = new JSDOM();
assert.equal(window.location.href, "about:blank");
});
specify("window.location.port for an about:blank window", () => {
const { window } = new JSDOM();
assert.equal(window.location.port, "");