Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { rehypeChipPunctuation } from "./markdownChipPunctuation";
4
5const text = (value: string) => ({ type: "text", value });
6const element = (tagName: string, children: object[]) => ({
7 type: "element",
8 tagName,
9 properties: {} as Record<string, unknown>,
10 children,
11});
12
13function paired(block: ReturnType<typeof element>) {
14 rehypeChipPunctuation()({ type: "root", children: [block] });
15 return block.children;
16}
17
18describe("rehypeChipPunctuation", () => {
19 it("pairs a link with the punctuation that follows it", () => {
20 const link = element("a", [text("a.ts")]);
21 expect(paired(element("p", [text("See "), link, text("... next")]))).toEqual([
22 text("See "),
23 expect.objectContaining({ tagName: "span", children: [link, text("...")] }),
24 text(" next"),
25 ]);
26 });
27
28 it("leaves code blocks alone", () => {
29 const children = [element("code", [text("a.ts")]), text(".")];
30 expect(paired(element("pre", [...children]))).toEqual(children);
31 });
32});