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

Function expectNestedTreeToMatch

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

Source from the content-addressed store, hash-verified

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