Skip to content

Commit 8802fe7

Browse files
committed
fix test for tooltipRenderAsHtml
1 parent 671af7d commit 8802fe7

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

src/packages/tour/tour.test.ts

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -614,41 +614,54 @@ describe("Tour", () => {
614614
});
615615

616616
describe("tooltipRenderAsHtml", () => {
617+
beforeEach(() => {
618+
document.body.innerHTML = ""; // Clear previous test DOM
619+
});
617620
test("should render HTML when tooltipRenderAsHtml is true", async () => {
618621
const tour = new Tour();
619622

620623
// Arrange & Act
621-
await tour
622-
.setOptions({
623-
tooltipRenderAsHtml: true,
624-
})
625-
.start();
624+
tour.setOptions({
625+
tooltipRenderAsHtml: true,
626+
steps: [
627+
{
628+
intro: "<b>Bold text</b> and <i>italic text</i>",
629+
},
630+
],
631+
});
626632

627-
tooltipText().innerHTML = "<b>Bold text</b> and <i>italic text</i>";
633+
await tour.start();
628634

629635
// Assert
630-
expect(content(tooltipText())).toBe(
631-
"<b>Bold text</b> and <i>italic text</i>"
632-
);
633-
expect(tooltipText().querySelector("b")?.textContent).toBe("Bold text");
634-
expect(tooltipText().querySelector("i")?.textContent).toBe("italic text");
636+
const tooltip = find(".introjs-tooltiptext");
637+
expect(tooltip).not.toBeNull();
638+
expect(tooltip?.querySelector("b")?.textContent).toBe("Bold text");
639+
expect(tooltip?.querySelector("i")?.textContent).toBe("italic text");
635640
});
641+
636642
test("should not render HTML when tooltipRenderAsHtml is false", async () => {
637643
const tour = new Tour();
638644

639645
// Arrange & Act
640-
await tour
641-
.setOptions({
642-
tooltipRenderAsHtml: false,
643-
})
644-
.start();
646+
tour.setOptions({
647+
tooltipRenderAsHtml: false,
648+
steps: [
649+
{
650+
intro: "<b>Bold text</b> and <i>italic text</i>",
651+
},
652+
],
653+
});
645654

646-
tooltipText().innerHTML = "<b>Bold text</b> and <i>italic text</i>";
655+
await tour.start();
647656

648657
// Assert
649-
expect(content(tooltipText())).toBe(
650-
"<b>Bold text</b> and <i>italic text</i>"
658+
const tooltip = find(".introjs-tooltiptext");
659+
expect(tooltip).not.toBeNull();
660+
expect(tooltip?.innerHTML).toContain(
661+
"&lt;b&gt;Bold text&lt;/b&gt; and &lt;i&gt;italic text&lt;/i&gt;"
651662
);
663+
expect(tooltip?.querySelector("b")).toBeNull();
664+
expect(tooltip?.querySelector("i")).toBeNull();
652665
});
653666
});
654667
});

0 commit comments

Comments
 (0)