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

Function expectNestedTreeToMatch

src/cdk/tree/tree-with-tree-control.spec.ts:1392–1433  ·  view source on GitHub ↗
(treeElement: Element, ...expectedTree: any[])

Source from the content-addressed store, hash-verified

1390}
1391
1392function expectNestedTreeToMatch(treeElement: Element, ...expectedTree: any[]) {
1393 const missedExpectations: string[] = [];
1394 function checkNodeContent(node: Element, expectedNode: any[]) {
1395 const expectedTextContent = expectedNode[expectedNode.length - 1];
1396 const actualTextContent = node.childNodes.item(0).textContent!.trim();
1397 if (actualTextContent !== expectedTextContent) {
1398 missedExpectations.push(
1399 `Expected node contents to be ${expectedTextContent} but was ${actualTextContent}`,
1400 );
1401 }
1402 }
1403
1404 function checkNodeDescendants(node: Element, expectedNode: any[], currentIndex: number) {
1405 let expectedDescendant = 0;
1406
1407 for (let i = currentIndex + 1; i < expectedTree.length; ++i) {
1408 if (expectedTree[i].length > expectedNode.length) {
1409 ++expectedDescendant;
1410 } else if (expectedTree[i].length === expectedNode.length) {
1411 break;
1412 }
1413 }
1414
1415 const actualDescendant = getNodes(node).length;
1416 if (actualDescendant !== expectedDescendant) {
1417 missedExpectations.push(
1418 `Expected node descendant num to be ${expectedDescendant} but was ${actualDescendant}`,
1419 );
1420 }
1421 }
1422
1423 getNodes(treeElement).forEach((node, index) => {
1424 const expected = expectedTree ? expectedTree[index] : null;
1425
1426 checkNodeDescendants(node, expected, index);
1427 checkNodeContent(node, expected);
1428 });
1429
1430 if (missedExpectations.length) {
1431 fail(missedExpectations.join('\n'));
1432 }
1433}
1434
1435@Component({
1436 template: `

Callers 1

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…