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

Function expectFlatTreeToMatch

src/cdk/tree/tree.spec.ts:1635–1674  ·  view source on GitHub ↗
(
  treeElement: Element,
  expectedPaddingIndent = 28,
  expectedPaddingUnits = 'px',
  ...expectedTree: any[]
)

Source from the content-addressed store, hash-verified

1633}
1634
1635function expectFlatTreeToMatch(
1636 treeElement: Element,
1637 expectedPaddingIndent = 28,
1638 expectedPaddingUnits = 'px',
1639 ...expectedTree: any[]
1640) {
1641 const missedExpectations: string[] = [];
1642
1643 function checkNode(node: Element, expectedNode: any[]) {
1644 const actualTextContent = node.textContent!.trim();
1645 const expectedTextContent = expectedNode[expectedNode.length - 1];
1646 if (actualTextContent !== expectedTextContent) {
1647 missedExpectations.push(
1648 `Expected node contents to be ${expectedTextContent} but was ${actualTextContent}`,
1649 );
1650 }
1651 }
1652
1653 function checkLevel(node: Element, expectedNode: any[]) {
1654 const rawLevel = (node as HTMLElement).style.paddingLeft;
1655
1656 // Some browsers return 0, while others return 0px.
1657 const actualLevel = rawLevel === '0' ? '0px' : rawLevel;
1658 const expectedLevel = `${expectedNode.length * expectedPaddingIndent}${expectedPaddingUnits}`;
1659 if (actualLevel != expectedLevel) {
1660 missedExpectations.push(`Expected node level to be ${expectedLevel} but was ${actualLevel}`);
1661 }
1662 }
1663
1664 getNodes(treeElement).forEach((node, index) => {
1665 const expected = expectedTree ? expectedTree[index] : null;
1666
1667 checkLevel(node, expected);
1668 checkNode(node, expected);
1669 });
1670
1671 if (missedExpectations.length) {
1672 fail(missedExpectations.join('\n'));
1673 }
1674}
1675
1676function expectNestedTreeToMatch(treeElement: Element, ...expectedTree: any[]) {
1677 const missedExpectations: string[] = [];

Callers 1

tree.spec.tsFile · 0.70

Calls 3

getNodesFunction · 0.70
checkLevelFunction · 0.70
checkNodeFunction · 0.70

Tested by

no test coverage detected