MCPcopy Create free account
hub / github.com/angular/components / expectNestedTreeToMatch

Function expectNestedTreeToMatch

src/cdk/tree/tree.spec.ts:1691–1732  ·  view source on GitHub ↗
(treeElement: Element, ...expectedTree: any[])

Source from the content-addressed store, hash-verified

1689}
1690
1691function expectNestedTreeToMatch(treeElement: Element, ...expectedTree: any[]) {
1692 const missedExpectations: string[] = [];
1693 function checkNodeContent(node: Element, expectedNode: any[]) {
1694 const expectedTextContent = expectedNode[expectedNode.length - 1];
1695 const actualTextContent = node.childNodes.item(0).textContent!.trim();
1696 if (actualTextContent !== expectedTextContent) {
1697 missedExpectations.push(
1698 `Expected node contents to be ${expectedTextContent} but was ${actualTextContent}`,
1699 );
1700 }
1701 }
1702
1703 function checkNodeDescendants(node: Element, expectedNode: any[], currentIndex: number) {
1704 let expectedDescendant = 0;
1705
1706 for (let i = currentIndex + 1; i < expectedTree.length; ++i) {
1707 if (expectedTree[i].length > expectedNode.length) {
1708 ++expectedDescendant;
1709 } else if (expectedTree[i].length === expectedNode.length) {
1710 break;
1711 }
1712 }
1713
1714 const actualDescendant = getNodes(node).length;
1715 if (actualDescendant !== expectedDescendant) {
1716 missedExpectations.push(
1717 `Expected node descendant num to be ${expectedDescendant} but was ${actualDescendant}`,
1718 );
1719 }
1720 }
1721
1722 getNodes(treeElement).forEach((node, index) => {
1723 const expected = expectedTree ? expectedTree[index] : null;
1724
1725 checkNodeDescendants(node, expected, index);
1726 checkNodeContent(node, expected);
1727 });
1728
1729 if (missedExpectations.length) {
1730 fail(missedExpectations.join('\n'));
1731 }
1732}
1733
1734@Component({
1735 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