(tableElement: Element, expected: string[][])
| 1113 | } |
| 1114 | |
| 1115 | export function expectTableToMatchContent(tableElement: Element, expected: string[][]) { |
| 1116 | const missedExpectations: string[] = []; |
| 1117 | function checkCellContent(actualCell: string, expectedCell: string) { |
| 1118 | if (actualCell !== expectedCell) { |
| 1119 | missedExpectations.push(`Expected cell contents to be ${expectedCell} but was ${actualCell}`); |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | const actual = getActualTableContent(tableElement); |
| 1124 | |
| 1125 | // Make sure the number of rows match |
| 1126 | if (actual.length !== expected.length) { |
| 1127 | missedExpectations.push(`Expected ${expected.length} total rows but got ${actual.length}`); |
| 1128 | fail(missedExpectations.join('\n')); |
| 1129 | } |
| 1130 | |
| 1131 | actual.forEach((row, rowIndex) => { |
| 1132 | const expectedRow = expected[rowIndex]; |
| 1133 | |
| 1134 | // Make sure the number of cells match |
| 1135 | if (row.length !== expectedRow.length) { |
| 1136 | missedExpectations.push(`Expected ${expectedRow.length} cells in row but got ${row.length}`); |
| 1137 | fail(missedExpectations.join('\n')); |
| 1138 | } |
| 1139 | |
| 1140 | row.forEach((actualCell, cellIndex) => { |
| 1141 | const expectedCell = expectedRow[cellIndex]; |
| 1142 | checkCellContent(actualCell, expectedCell); |
| 1143 | }); |
| 1144 | }); |
| 1145 | |
| 1146 | if (missedExpectations.length) { |
| 1147 | fail(missedExpectations.join('\n')); |
| 1148 | } |
| 1149 | } |
no test coverage detected