import { describe, expect, it } from "vitest"; import { generateExcerpt } from "@/lib/excerpt"; describe("generateExcerpt (HTML bodies)", () => { it("strips tags but keeps the visible text", () => { const html = "
Some bold text with a link. And more.
"; expect(generateExcerpt(html, 100)).toBe("Heading Some bold text with a link. And more."); }); it("caps the excerpt at the word limit and appends an ellipsis", () => { expect(generateExcerpt("one two three four five six
", 3)).toBe("one two three…"); }); it("adds no ellipsis when the text fits exactly", () => { expect(generateExcerpt("one two three
", 3)).toBe("one two three"); }); it("skips code blocks entirely", () => { const html = "const hidden = true;After the code.
"; expect(generateExcerpt(html, 50)).toBe("After the code."); }); it("contributes nothing from images (alt text is not visible text)", () => { const html = '
Caption text.
'; expect(generateExcerpt(html, 50)).toBe("Caption text."); }); it("keeps inline code as text", () => { expect(generateExcerpt("Run npm test daily.
| cell one | cell two |

alpha beta
", 0)).toBe("alpha…"); }); });