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

Function expectFlatTreeToMatch

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

Source from the content-addressed store, hash-verified

1349}
1350
1351function expectFlatTreeToMatch(
1352 treeElement: Element,
1353 expectedPaddingIndent = 28,
1354 expectedPaddingUnits = 'px',
1355 ...expectedTree: any[]
1356) {
1357 const missedExpectations: string[] = [];
1358
1359 function checkNode(node: Element, expectedNode: any[]) {
1360 const actualTextContent = node.textContent!.trim();
1361 const expectedTextContent = expectedNode[expectedNode.length - 1];
1362 if (actualTextContent !== expectedTextContent) {
1363 missedExpectations.push(
1364 `Expected node contents to be ${expectedTextContent} but was ${actualTextContent}`,
1365 );
1366 }
1367 }
1368
1369 function checkLevel(node: Element, expectedNode: any[]) {
1370 const rawLevel = (node as HTMLElement).style.paddingLeft;
1371
1372 // Some browsers return 0, while others return 0px.
1373 const actualLevel = rawLevel === '0' ? '0px' : rawLevel;
1374 const expectedLevel = `${expectedNode.length * expectedPaddingIndent}${expectedPaddingUnits}`;
1375 if (actualLevel != expectedLevel) {
1376 missedExpectations.push(`Expected node level to be ${expectedLevel} but was ${actualLevel}`);
1377 }
1378 }
1379
1380 getNodes(treeElement).forEach((node, index) => {
1381 const expected = expectedTree ? expectedTree[index] : null;
1382
1383 checkLevel(node, expected);
1384 checkNode(node, expected);
1385 });
1386
1387 if (missedExpectations.length) {
1388 fail(missedExpectations.join('\n'));
1389 }
1390}
1391
1392function expectNestedTreeToMatch(treeElement: Element, ...expectedTree: any[]) {
1393 const missedExpectations: string[] = [];

Callers 1

Calls 3

getNodesFunction · 0.70
checkLevelFunction · 0.70
checkNodeFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…