From 766c128b745b94825e8b9c9a9ce55bc87c5db722 Mon Sep 17 00:00:00 2001 From: Lee Wannacott Date: Sun, 21 May 2023 16:40:10 +1200 Subject: [PATCH] Fix: for if table.body is null (#99) --- public/table-sort.js | 2 ++ test/missingTableTags.test.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/public/table-sort.js b/public/table-sort.js index be7e136..4eaf139 100644 --- a/public/table-sort.js +++ b/public/table-sort.js @@ -54,6 +54,7 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { return sortableTable.querySelector("tbody"); } } else { + // if or exists below the browser will make return sortableTable.querySelector("tbody"); } } @@ -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"); diff --git a/test/missingTableTags.test.js b/test/missingTableTags.test.js index 3156316..7433c8e 100644 --- a/test/missingTableTags.test.js +++ b/test/missingTableTags.test.js @@ -13,7 +13,7 @@ test("test no missing table tags - (user has put and )", () => { ).toStrictEqual(["Alpha", "Bravo", "Charlie", "Delta", "Echo"]); }); -test("test with missing tag - (tbody and thead exist)", () => { +test("test with missing tag - thead exist", () => { expect( createTestTableMissingBodyTag([ "Echo", @@ -37,7 +37,7 @@ test("test with missing tag)", () => { ).toStrictEqual(["Alpha", "Bravo", "Charlie", "Delta", "Echo"]); }); -test("test with missing and tags - (tbody and thead exist)", () => { +test("test with missing and tags", () => { expect( createTestTableMissingBodyAndHeadTag([ "Echo",