Skip to content

Commit da61425

Browse files
committed
fix js tests
1 parent 54c82ca commit da61425

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

gateway/sds_gateway/static/js/core/__tests__/DOMUtils.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55

66
import { DOMUtils } from "../DOMUtils.js";
77

8+
/** Approximate Element.textContent from innerHTML for mock nodes (strip tags, decode entities). */
9+
function mockTextContentFromHtml(html) {
10+
if (html == null || html === "") return "";
11+
const noTags = String(html).replace(/<[^>]*>/g, "");
12+
return noTags
13+
.replace(/&lt;/g, "<")
14+
.replace(/&gt;/g, ">")
15+
.replace(/&amp;/g, "&");
16+
}
17+
818
describe("DOMUtils", () => {
919
let domUtils;
1020
let mockAPIClient;
@@ -27,6 +37,12 @@ describe("DOMUtils", () => {
2737
querySelector: jest.fn(),
2838
querySelectorAll: jest.fn(() => []),
2939
};
40+
Object.defineProperty(mockContainer, "textContent", {
41+
get() {
42+
return mockTextContentFromHtml(this.innerHTML);
43+
},
44+
configurable: true,
45+
});
3046

3147
mockToastContainer = {
3248
id: "toast-container",

0 commit comments

Comments
 (0)