react / wstein / node_modules / jest-cli / node_modules / jsdom / node_modules / htmlparser2 / node_modules / domutils / test / tests / helpers.js
81153 viewsvar makeDom = require("../utils").makeDom;1var helpers = require("../..");2var assert = require("assert");34describe("helpers", function() {5describe("removeSubsets", function() {6var removeSubsets = helpers.removeSubsets;7var dom = makeDom("<div><p><span></span></p><p></p></div>")[0];89it("removes identical trees", function() {10var matches = removeSubsets([dom, dom]);11assert.equal(matches.length, 1);12});1314it("Removes subsets found first", function() {15var matches = removeSubsets([dom, dom.children[0].children[0]]);16assert.equal(matches.length, 1);17});1819it("Removes subsets found last", function() {20var matches = removeSubsets([dom.children[0], dom]);21assert.equal(matches.length, 1);22});2324it("Does not remove unique trees", function() {25var matches = removeSubsets([dom.children[0], dom.children[1]]);26assert.equal(matches.length, 2);27});28});2930describe("compareDocumentPosition", function() {31var compareDocumentPosition = helpers.compareDocumentPosition;32var markup = "<div><p><span></span></p><a></a></div>";33var dom = makeDom(markup)[0];34var p = dom.children[0];35var span = p.children[0];36var a = dom.children[1];3738it("reports when the first node occurs before the second indirectly", function() {39assert.equal(compareDocumentPosition(span, a), 2);40});4142it("reports when the first node contains the second", function() {43assert.equal(compareDocumentPosition(p, span), 10);44});4546it("reports when the first node occurs after the second indirectly", function() {47assert.equal(compareDocumentPosition(a, span), 4);48});4950it("reports when the first node is contained by the second", function() {51assert.equal(compareDocumentPosition(span, p), 20);52});5354it("reports when the nodes belong to separate documents", function() {55var other = makeDom(markup)[0].children[0].children[0];5657assert.equal(compareDocumentPosition(span, other), 1);58});5960it("reports when the nodes are identical", function() {61assert.equal(compareDocumentPosition(span, span), 0);62});63});6465describe("uniqueSort", function() {66var uniqueSort = helpers.uniqueSort;67var dom, p, span, a;6869beforeEach(function() {70dom = makeDom("<div><p><span></span></p><a></a></div>")[0];71p = dom.children[0];72span = p.children[0];73a = dom.children[1];74});7576it("leaves unique elements untouched", function() {77assert.deepEqual(uniqueSort([p, a]), [p, a]);78});7980it("removes duplicate elements", function() {81assert.deepEqual(uniqueSort([p, a, p]), [p, a]);82});8384it("sorts nodes in document order", function() {85assert.deepEqual(uniqueSort([a, dom, span, p]), [dom, p, span, a]);86});87});88});899091