Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

openPullRequestLink.test.ts

30 lines1.1 KB

1import { describe, expect, it, vi } from "vite-plus/test";
2​
3import { openPullRequestLink, PullRequestLinkOpenError } from "./openPullRequestLink";
4​
5describe("openPullRequestLink", () => {
6 it("opens the requested pull request URL", async () => {
7 const openExternal = vi.fn(async () => undefined);
8 const targetUrl = "https://github.com/pingdotgg/t3code/pull/123";
9​
10 await openPullRequestLink({ openExternal }, targetUrl);
11​
12 expect(openExternal).toHaveBeenCalledExactlyOnceWith(targetUrl);
13 });
14​
15 it("reports bridge failures with a safe target origin", async () => {
16 const cause = new Error("desktop shell unavailable");
17 const targetUrl = "https://github.com/pingdotgg/t3code/pull/123?token=secret";
18 const openExternal = vi.fn(async () => Promise.reject(cause));
19​
20 const result = openPullRequestLink({ openExternal }, targetUrl);
21​
22 await expect(result).rejects.toEqual(
23 new PullRequestLinkOpenError({
24 targetOrigin: "https://github.com",
25 cause,
26 }),
27 );
28 await expect(result).rejects.not.toHaveProperty("message", expect.stringContaining("secret"));
29 });
30});