Skip to content

Commit e3473a7

Browse files
committed
test: add tests for declarationSignatureToHtml
1 parent b129db8 commit e3473a7

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { expect, test } from "vitest";
2+
import { declarationSignatureToHtml } from "./declaration-signature-to-html";
3+
4+
test("variable", async () => {
5+
await expect(
6+
declarationSignatureToHtml(
7+
{
8+
kind: "variable",
9+
id: "foo",
10+
name: "foo",
11+
docs: [],
12+
file: "foo.ts",
13+
line: 123,
14+
signature: "const foo: Bar;",
15+
},
16+
(s) => (s === "Bar" ? "bar.ts#L789" : undefined),
17+
),
18+
).resolves.toMatchInlineSnapshot(
19+
`"<pre class="shiki shiki-themes github-light github-dark" style="background-color:#f7f7f7;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#D73A49;--shiki-dark:#F97583">const</span><span style="color:#24292E;--shiki-dark:#E1E4E8"> </span><span style="color:#005CC5;--shiki-dark:#79B8FF">foo</span><span style="color:#D73A49;--shiki-dark:#F97583">:</span><span style="color:#24292E;--shiki-dark:#E1E4E8"> </span><a style="color:#6F42C1;--shiki-dark:#B392F0" href="bar.ts#L789">Bar</a><span style="color:#24292E;--shiki-dark:#E1E4E8">;</span></span></code></pre>"`,
20+
);
21+
});
22+
23+
test("class property", async () => {
24+
await expect(
25+
declarationSignatureToHtml(
26+
{
27+
kind: "class-property",
28+
id: "Foo.bar",
29+
name: "bar",
30+
docs: [],
31+
file: "foo.ts",
32+
line: 123,
33+
signature: "readonly bar: Bar;",
34+
},
35+
(s) => (s === "Bar" ? "bar.ts#L789" : undefined),
36+
),
37+
).resolves.toMatchInlineSnapshot(`"<pre class="shiki shiki-themes github-light github-dark" style="background-color:#f7f7f7;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#D73A49;--shiki-dark:#F97583">readonly</span><span style="color:#24292E;--shiki-dark:#E1E4E8"> </span><span style="color:#E36209;--shiki-dark:#FFAB70">bar</span><span style="color:#D73A49;--shiki-dark:#F97583">:</span><span style="color:#24292E;--shiki-dark:#E1E4E8"> </span><a style="color:#6F42C1;--shiki-dark:#B392F0" href="bar.ts#L789">Bar</a><span style="color:#24292E;--shiki-dark:#E1E4E8">;</span></span></code></pre>"`);
38+
});
39+
40+
test("don't link from function parameter name", async () => {
41+
await expect(
42+
declarationSignatureToHtml(
43+
{
44+
kind: "function",
45+
id: "foo",
46+
name: "foo",
47+
docs: [],
48+
file: "foo.ts",
49+
line: 123,
50+
signature: "(bar: Bar) => Bar;",
51+
},
52+
(s) => (s.toLowerCase() === "bar" ? "bar.ts#L789" : undefined),
53+
),
54+
).resolves.toMatchInlineSnapshot(
55+
`"<pre class="shiki shiki-themes github-light github-dark" style="background-color:#f7f7f7;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#24292E;--shiki-dark:#E1E4E8">(</span><span style="color:#E36209;--shiki-dark:#FFAB70">bar</span><span style="color:#D73A49;--shiki-dark:#F97583">:</span><span style="color:#24292E;--shiki-dark:#E1E4E8"> </span><a style="color:#6F42C1;--shiki-dark:#B392F0" href="bar.ts#L789">Bar</a><span style="color:#24292E;--shiki-dark:#E1E4E8">) </span><span style="color:#D73A49;--shiki-dark:#F97583">=&gt;</span><span style="color:#24292E;--shiki-dark:#E1E4E8"> </span><a style="color:#6F42C1;--shiki-dark:#B392F0" href="bar.ts#L789">Bar</a><span style="color:#24292E;--shiki-dark:#E1E4E8">;</span></span></code></pre>"`,
56+
);
57+
});

0 commit comments

Comments
 (0)