(tableElement: Element, expected: any[])
| 3471 | } |
| 3472 | |
| 3473 | export function expectTableToMatchContent(tableElement: Element, expected: any[]) { |
| 3474 | const missedExpectations: string[] = []; |
| 3475 | function checkCellContent(actualCell: string, expectedCell: string) { |
| 3476 | if (actualCell !== expectedCell) { |
| 3477 | missedExpectations.push(`Expected cell contents to be ${expectedCell} but was ${actualCell}`); |
| 3478 | } |
| 3479 | } |
| 3480 | |
| 3481 | const actual = getActualTableContent(tableElement); |
| 3482 | |
| 3483 | // Make sure the number of rows match |
| 3484 | if (actual.length !== expected.length) { |
| 3485 | missedExpectations.push(`Expected ${expected.length} total rows but got ${actual.length}`); |
| 3486 | fail(missedExpectations.join('\n')); |
| 3487 | } |
| 3488 | |
| 3489 | actual.forEach((row, rowIndex) => { |
| 3490 | const expectedRow = expected[rowIndex]; |
| 3491 | |
| 3492 | // Make sure the number of cells match |
| 3493 | if (row.length !== expectedRow.length) { |
| 3494 | missedExpectations.push(`Expected ${expectedRow.length} cells in row but got ${row.length}`); |
| 3495 | fail(missedExpectations.join('\n')); |
| 3496 | } |
| 3497 | |
| 3498 | row.forEach((actualCell, cellIndex) => { |
| 3499 | const expectedCell = expectedRow ? expectedRow[cellIndex] : null; |
| 3500 | checkCellContent(actualCell, expectedCell); |
| 3501 | }); |
| 3502 | }); |
| 3503 | |
| 3504 | if (missedExpectations.length) { |
| 3505 | fail(missedExpectations.join('\n')); |
| 3506 | } |
| 3507 | } |
no test coverage detected