app-walkthrough
Version:
An intuitive guided walkthrough library with UI highlighting and voice narration for web apps.
46 lines (45 loc) • 1.74 kB
JavaScript
import { hasTextContent } from "../findElement";
import { JSDOM } from "jsdom";
describe("hasTextContent", () => {
let container;
beforeEach(() => {
const dom = new JSDOM(`
<div>
<button>Click Me</button>
<span>Sample Text</span>
<div>Another Text</div>
</div>
`);
container = dom.window.document.body;
});
it("returns true if element contains the text", () => {
const button = container.querySelector("button");
expect(button).not.toBeNull();
if (!button)
throw new Error("Button element not found");
expect(hasTextContent(button, "Click", true)).toBe(true);
});
it("returns false if element does not contain the text", () => {
const span = container.querySelector("span");
expect(span).not.toBeNull();
if (!span)
throw new Error("Span element not found");
expect(hasTextContent(span, "Missing", true)).toBe(false);
});
it("is case-insensitive if caseSensitive is false", () => {
const div = container.querySelector("div div");
expect(div).not.toBeNull();
if (!div)
throw new Error("Div element not found");
expect(hasTextContent(div, "another text", false)).toBe(true);
expect(hasTextContent(div, "ANOTHER TEXT", false)).toBe(true);
});
it("is case-sensitive by default", () => {
const div = container.querySelector("div div");
expect(div).not.toBeNull();
if (!div)
throw new Error("Div element not found");
expect(hasTextContent(div, "Another Text", true)).toBe(true);
expect(hasTextContent(div, "another text", true)).toBe(false);
});
});