Skip to content

Commit

Permalink
Fix: for if table.body is null (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeWannacott committed May 21, 2023
1 parent d678d57 commit 766c128
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions public/table-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
return sortableTable.querySelector("tbody");
}
} else {
// if <tr> or <td> exists below <thead> the browser will make <tbody>
return sortableTable.querySelector("tbody");
}
}
Expand Down Expand Up @@ -110,6 +111,7 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
body: getTableBody(sortableTable),
head: sortableTable.querySelector("thead"),
};
if(table.body == null){ return }
table.headers = table.head.querySelectorAll("th");
table.rows = table.body.querySelectorAll("tr");

Expand Down
4 changes: 2 additions & 2 deletions test/missingTableTags.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test("test no missing table tags - (user has put <tbody> and <thead>)", () => {
).toStrictEqual(["Alpha", "Bravo", "Charlie", "Delta", "Echo"]);
});

test("test with missing <tbody> tag - (tbody and thead exist)", () => {
test("test with missing <tbody> tag - thead exist", () => {
expect(
createTestTableMissingBodyTag([
"Echo",
Expand All @@ -37,7 +37,7 @@ test("test with missing <thead> tag)", () => {
).toStrictEqual(["Alpha", "Bravo", "Charlie", "Delta", "Echo"]);
});

test("test with missing <tbody> and <thead> tags - (tbody and thead exist)", () => {
test("test with missing <tbody> and <thead> tags", () => {
expect(
createTestTableMissingBodyAndHeadTag([
"Echo",
Expand Down

0 comments on commit 766c128

Please sign in to comment.