MCPcopy Index your code
hub / github.com/angular/components / expectNestedTreeToMatch

Function expectNestedTreeToMatch

src/material/tree/tree.spec.ts:807–848  ·  view source on GitHub ↗
(treeElement: Element, ...expectedTree: TreeContent)

Source from the content-addressed store, hash-verified

805}
806
807function expectNestedTreeToMatch(treeElement: Element, ...expectedTree: TreeContent) {
808 const missedExpectations: string[] = [];
809 function checkNodeContent(node: Element, expectedNode: NodeContent) {
810 const expectedTextContent = expectedNode[expectedNode.length - 1];
811 const actualTextContent = node.childNodes.item(0).textContent!.trim();
812 if (actualTextContent !== expectedTextContent) {
813 missedExpectations.push(
814 `Expected node contents to be ${expectedTextContent} but was ${actualTextContent}`,
815 );
816 }
817 }
818
819 function checkNodeDescendants(node: Element, expectedNode: NodeContent, currentIndex: number) {
820 let expectedDescendant = 0;
821
822 for (let i = currentIndex + 1; i < expectedTree.length; ++i) {
823 if (expectedTree[i].length > expectedNode.length) {
824 ++expectedDescendant;
825 } else if (expectedTree[i].length === expectedNode.length) {
826 break;
827 }
828 }
829
830 const actualDescendant = getNodes(node).length;
831 if (actualDescendant !== expectedDescendant) {
832 missedExpectations.push(
833 `Expected node descendant num to be ${expectedDescendant} but was ${actualDescendant}`,
834 );
835 }
836 }
837
838 getNodes(treeElement).forEach((node, index) => {
839 const expected = expectedTree[index];
840
841 checkNodeDescendants(node, expected, index);
842 checkNodeContent(node, expected);
843 });
844
845 if (missedExpectations.length) {
846 fail(missedExpectations.join('\n'));
847 }
848}
849
850@Component({
851 template: `

Callers 1

tree.spec.tsFile · 0.70

Calls 3

getNodesFunction · 0.70
checkNodeDescendantsFunction · 0.70
checkNodeContentFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…