(treeElement: Element, ...expectedTree: TreeContent)
| 805 | } |
| 806 | |
| 807 | function expectNestedTreeToMatch(treeElement: Element, ...expectedTree: TreeContent) { |
| 808 | const missedExpectations: string[] = []; |
| 809 | function checkNodeContent(node: Element, expectedNode: NodeContent) { |
| 810 | const expectedTextContent = expectedNode[expectedNode.length - 1]; |
| 811 | const actualTextContent = node.childNodes.item(0).textContent!.trim(); |
| 812 | if (actualTextContent !== expectedTextContent) { |
| 813 | missedExpectations.push( |
| 814 | `Expected node contents to be ${expectedTextContent} but was ${actualTextContent}`, |
| 815 | ); |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | function checkNodeDescendants(node: Element, expectedNode: NodeContent, currentIndex: number) { |
| 820 | let expectedDescendant = 0; |
| 821 | |
| 822 | for (let i = currentIndex + 1; i < expectedTree.length; ++i) { |
| 823 | if (expectedTree[i].length > expectedNode.length) { |
| 824 | ++expectedDescendant; |
| 825 | } else if (expectedTree[i].length === expectedNode.length) { |
| 826 | break; |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | const actualDescendant = getNodes(node).length; |
| 831 | if (actualDescendant !== expectedDescendant) { |
| 832 | missedExpectations.push( |
| 833 | `Expected node descendant num to be ${expectedDescendant} but was ${actualDescendant}`, |
| 834 | ); |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | getNodes(treeElement).forEach((node, index) => { |
| 839 | const expected = expectedTree[index]; |
| 840 | |
| 841 | checkNodeDescendants(node, expected, index); |
| 842 | checkNodeContent(node, expected); |
| 843 | }); |
| 844 | |
| 845 | if (missedExpectations.length) { |
| 846 | fail(missedExpectations.join('\n')); |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | @Component({ |
| 851 | template: ` |
no test coverage detected
searching dependent graphs…