Commit b3d76b42 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Move `textNodes` into DOM test utilities for reuse

parent 5b16545a
import { TextPosition, TextRange, ResolveDirection } from '../text-range';
import { assertNodesEqual } from '../../../test-util/compare-dom';
import { assertNodesEqual, textNodes } from '../../../test-util/compare-dom';
const html = `
<main>
......@@ -12,22 +12,6 @@ const html = `
</main>
`;
/**
* Return all the `Text` descendants of `node`
*
* @param {Node} node
* @return {Text[]}
*/
function textNodes(node) {
const nodes = [];
const iter = document.createNodeIterator(node, NodeFilter.SHOW_TEXT);
let current;
while ((current = iter.nextNode())) {
nodes.push(current);
}
return nodes;
}
describe('annotator/anchoring/text-range', () => {
describe('TextPosition', () => {
let container;
......
......@@ -46,3 +46,19 @@ export function assertNodesEqual(actual, expected) {
);
}
}
/**
* Return all the `Text` descendants of `node`
*
* @param {Node} node
* @return {Text[]}
*/
export function textNodes(node) {
const nodes = [];
const iter = document.createNodeIterator(node, NodeFilter.SHOW_TEXT);
let current;
while ((current = iter.nextNode())) {
nodes.push(current);
}
return nodes;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment