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>
t("ID Selector on Form with an input that has a name of 'id'", "#lengthtest", ["lengthtest"]);
t("ID selector with non-existant ancestor", "#asdfasdf #foobar", []); // bug #986
deepEqual(Sizzle("div#form", document.body), [], "ID selector within the context of another element");
t("Underscore ID", "#types_all", ["types_all"]);
t("Dash ID", "#fx-queue", ["fx-queue"]);
t("ID with weird characters in it", "#name\\+value", ["name+value"]);
}
}), {
async: true
});
specify('class', test(function (window) {
with (window) {
t("Class Selector", ".blog", ["mark", "simon"]);
t("Class Selector", ".GROUPS", ["groups"]);
t("Class Selector", ".blog.link", ["simon"]);
t("Class Selector w/ Element", "a.blog", ["mark", "simon"]);
t("Parent Class Selector", "p .blog", ["mark", "simon"]);
t("Class selector using UTF8", ".台北Táiběi", ["utf8class1"]);
//t( "Class selector using UTF8", ".台北", ["utf8class1","utf8class2"] );
t("Class selector using UTF8", ".台北Táiběi.台北", ["utf8class1"]);
t("Class selector using UTF8", ".台北Táiběi, .台北", ["utf8class1", "utf8class2"]);
t("Descendant class selector using UTF8", "div .台北Táiběi", ["utf8class1"]);
t("Child class selector using UTF8", "form > .台北Táiběi", ["utf8class1"]);
t("Escaped Class", ".foo\\:bar", ["foo:bar"]);
broken("Only-child", ":only-child(n)");
// Make sure attribute value quoting works correctly. See: #6093
var attrbad = jQuery('<input id="attrbad1" name="foo.baz" value="2" type="hidden"><input id="attrbad2" name="foo[baz]" value="2" type="hidden">').appendTo("body");
broken("Attribute not escaped", "input[name=foo.baz]", []);
// Shouldn't be matching those inner brackets
broken("Attribute not escaped", "input[name=foo[baz]]", []);
attrbad.remove();
}
}), {
async: true
});
specify('id', test(function (window) {
with (window) {
t("ID Selector", "#body", ["body"]);
t("ID Selector w/ Element", "body#body", ["body"]);
t("ID Selector w/ Element", "ul#first", []);
t("ID selector with existing ID descendant", "#firstp #simon1", ["simon1"]);
t("ID selector with non-existant descendant", "#firstp #foobar", []);
t("ID selector using UTF8", "#台北Táiběi", ["台北Táiběi"]);
t("Multiple ID selectors using UTF8", "#台北Táiběi, #台北", ["台北Táiběi", "台北"]);
t("Descendant ID selector using UTF8", "div #台北", ["台北"]);
t("Child ID selector using UTF8", "form > #台北", ["台北"]);
t("Escaped ID", "#foo\\:bar", ["foo:bar"]);
t("Escaped ID with descendent", "#foo\\:bar span:not(:input)", ["foo_descendent"]);
t("Escaped ID", "#test\\.foo\\[5\\]bar", ["test.foo[5]bar"]);
t("Descendant escaped ID", "div #foo\\:bar", ["foo:bar"]);
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'));
assert.equal(el.classList[0], "foo");
// add one token twice
el.classList.add("foo", "foo");
assert.equal(el.className, "foo");
assert.equal(el.classList[0], "foo");
// add two distinct tokens
el.className = "";
el.classList.add("foo", "bar");
assert.equal(el.className, "foo bar");
assert.equal(el.classList[0], "foo");
assert.equal(el.classList[1], "bar");
});
specify(".add() throws if a token is empty", () => {
function block() {
el.classList.add("foo", "");
}
assert.throwsDomException(block, el.ownerDocument, "SyntaxError");
});
specify(".add() throws if a token contains whitespace", () => {
function block() {
el.classList.add(" foo", "bar");
}
assert.throwsDomException(block, el.ownerDocument, "InvalidCharacterError");
});
specify(".remove(tokens...) removes provided tokens", () => {
error: errorObj
});
doc.defaultView.dispatchEvent(e);
},
{
async: true
}
);
const proxied = [
"onblur", "onerror", "onfocus", "onload", "onresize", "onscroll", "onafterprint",
"onbeforeprint", "onbeforeunload", "onhashchange", "onlanguagechange", "onmessage", "onoffline", "ononline",
"onpagehide", "onpageshow", "onpopstate", "onstorage", "onunload"
];
specify(
"proxied body/window event handlers: setting on body as properties reflects on window",
() => {
const doc = (new JSDOM()).window.document;
for (const name of proxied) {
function handler() {
// doesn't matter for this test
}
doc.body[name] = handler;
assert.equal(doc.body[name], handler, `${name} should be set on the body correctly`);
assert.equal(doc.defaultView[name], handler, `${name} should be set on the window correctly`);
doc.body[name] = null;
assert.equal(doc.body[name], null, `${name} should be unset on the body correctly`);
assert.equal(doc.defaultView[name], null, `${name} should be unset on the window correctly`);
"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', () => {
.appendTo("#qunit-fixture").children();
equal(a.length, 3, "Make sure the right number of elements were inserted.");
equal(a[1].id, "tName2ID", "Make sure the right number of elements were inserted.");
equal(Sizzle("[name=tName1]")[0], a[0], "Find elements that have similar IDs");
equal(Sizzle("[name=tName2]")[0], a[1], "Find elements that have similar IDs");
t("Find elements that have similar IDs", "#tName2ID", ["tName2ID"]);
a.parent().remove();
}
}), {
async: true
});
specify('multiple', test(function (window) {
with (window) {
t("Comma Support", "h2, #qunit-fixture p", ["qunit-banner", "qunit-userAgent", "firstp", "ap", "sndp", "en", "sap", "first"]);
t("Comma Support", "h2 , #qunit-fixture p", ["qunit-banner", "qunit-userAgent", "firstp", "ap", "sndp", "en", "sap", "first"]);
t("Comma Support", "h2 , #qunit-fixture p", ["qunit-banner", "qunit-userAgent", "firstp", "ap", "sndp", "en", "sap", "first"]);
t("Comma Support", "h2,#qunit-fixture p", ["qunit-banner", "qunit-userAgent", "firstp", "ap", "sndp", "en", "sap", "first"]);
t("Comma Support", "h2,#qunit-fixture p ", ["qunit-banner", "qunit-userAgent", "firstp", "ap", "sndp", "en", "sap", "first"]);
t("Comma Support", "h2\t,\r#qunit-fixture p\n", ["qunit-banner", "qunit-userAgent", "firstp", "ap", "sndp", "en", "sap", "first"]);
}
}), {
async: true
});
specify('child and adjacent', test(function (window) {
with (window) {
t("Child", "p > a", ["simon1", "google", "groups", "mark", "yahoo", "simon"]);
t("Child", "p> a", ["simon1", "google", "groups", "mark", "yahoo", "simon"]);