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

Function expectNestedTreeToMatch

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

Source from the content-addressed store, hash-verified

1674}
1675
1676function expectNestedTreeToMatch(treeElement: Element, ...expectedTree: any[]) {
1677 const missedExpectations: string[] = [];
1678 function checkNodeContent(node: Element, expectedNode: any[]) {
1679 const expectedTextContent = expectedNode[expectedNode.length - 1];
1680 const actualTextContent = node.childNodes.item(0).textContent!.trim();
1681 if (actualTextContent !== expectedTextContent) {
1682 missedExpectations.push(
1683 `Expected node contents to be ${expectedTextContent} but was ${actualTextContent}`,
1684 );
1685 }
1686 }
1687
1688 function checkNodeDescendants(node: Element, expectedNode: any[], currentIndex: number) {
1689 let expectedDescendant = 0;
1690
1691 for (let i = currentIndex + 1; i < expectedTree.length; ++i) {
1692 if (expectedTree[i].length > expectedNode.length) {
1693 ++expectedDescendant;
1694 } else if (expectedTree[i].length === expectedNode.length) {
1695 break;
1696 }
1697 }
1698
1699 const actualDescendant = getNodes(node).length;
1700 if (actualDescendant !== expectedDescendant) {
1701 missedExpectations.push(
1702 `Expected node descendant num to be ${expectedDescendant} but was ${actualDescendant}`,
1703 );
1704 }
1705 }
1706
1707 getNodes(treeElement).forEach((node, index) => {
1708 const expected = expectedTree ? expectedTree[index] : null;
1709
1710 checkNodeDescendants(node, expected, index);
1711 checkNodeContent(node, expected);
1712 });
1713
1714 if (missedExpectations.length) {
1715 fail(missedExpectations.join('\n'));
1716 }
1717}
1718
1719@Component({
1720 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…