Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

test(web): prefer optional chaining in schema unit tests

Richie McIlroyba966d4d9fbb
diff --git a/apps/web/__tests__/unit/async-video-code-reviews-page.test.ts b/apps/web/__tests__/unit/async-video-code-reviews-page.test.ts
index 73b8b3424..33eb89ead 100644
--- a/apps/web/__tests__/unit/async-video-code-reviews-page.test.ts
+++ b/apps/web/__tests__/unit/async-video-code-reviews-page.test.ts
@@ -151,7 +151,7 @@ describe("AsyncVideoCodeReviewsPage FAQ schema", () => {
name: "What is an async video code review?",
acceptedAnswer: {
"@type": "Answer",
- text: faqs[0]!.answer,
+ text: faqs[0]?.answer,
},
});
});
diff --git a/apps/web/__tests__/unit/avi-to-mp4-page.test.ts b/apps/web/__tests__/unit/avi-to-mp4-page.test.ts
index 608096356..9add737c2 100644
--- a/apps/web/__tests__/unit/avi-to-mp4-page.test.ts
+++ b/apps/web/__tests__/unit/avi-to-mp4-page.test.ts
@@ -119,7 +119,7 @@ describe("AVI to MP4 FAQ schema validity", () => {
name: "How do I convert AVI to MP4 online?",
acceptedAnswer: {
"@type": "Answer",
- text: faqs[0]!.answer,
+ text: faqs[0]?.answer,
},
});
});
@@ -169,11 +169,11 @@ describe("AVI to MP4 HowTo schema validity", () => {
steps: howToSteps,
});
- expect(schema.step[0]!.position).toBe(1);
- expect(schema.step[0]!.name).toBe("Upload your AVI file");
- expect(schema.step[1]!.position).toBe(2);
- expect(schema.step[2]!.position).toBe(3);
- expect(schema.step[2]!.name).toBe("Download your MP4");
+ expect(schema.step[0]?.position).toBe(1);
+ expect(schema.step[0]?.name).toBe("Upload your AVI file");
+ expect(schema.step[1]?.position).toBe(2);
+ expect(schema.step[2]?.position).toBe(3);
+ expect(schema.step[2]?.name).toBe("Download your MP4");
});
it("produces JSON-serializable output", () => {
diff --git a/apps/web/__tests__/unit/best-screen-recorder-page.test.ts b/apps/web/__tests__/unit/best-screen-recorder-page.test.ts
index 03e6f89d0..9a9057ecc 100644
--- a/apps/web/__tests__/unit/best-screen-recorder-page.test.ts
+++ b/apps/web/__tests__/unit/best-screen-recorder-page.test.ts
@@ -143,15 +143,15 @@ describe("BestScreenRecorderPage FAQ schema", () => {
name: "What is the best screen recorder?",
acceptedAnswer: {
"@type": "Answer",
- text: faqs[0]!.answer,
+ text: faqs[0]?.answer,
},
});
});
it("strips HTML tags from answers", () => {
const schema = createFAQSchema(faqs);
- expect(schema.mainEntity[1]!.acceptedAnswer.text).not.toContain("<a");
- expect(schema.mainEntity[1]!.acceptedAnswer.text).toContain("Cap free");
+ expect(schema.mainEntity[1]?.acceptedAnswer.text).not.toContain("<a");
+ expect(schema.mainEntity[1]?.acceptedAnswer.text).toContain("Cap free");
});
it("produces JSON-serializable output", () => {
diff --git a/apps/web/__tests__/unit/breadcrumb-schema.test.ts b/apps/web/__tests__/unit/breadcrumb-schema.test.ts
index e86f5b37e..e37ccc1f3 100644
--- a/apps/web/__tests__/unit/breadcrumb-schema.test.ts
+++ b/apps/web/__tests__/unit/breadcrumb-schema.test.ts
@@ -35,8 +35,8 @@ describe("createBreadcrumbSchema", () => {
name: "Tools",
item: "https://cap.so/tools",
});
- expect(schema.itemListElement[2]!.position).toBe(3);
- expect(schema.itemListElement[2]!.name).toBe("Convert");
+ expect(schema.itemListElement[2]?.position).toBe(3);
+ expect(schema.itemListElement[2]?.name).toBe("Convert");
});
it("omits item field when no url is provided", () => {
@@ -45,7 +45,7 @@ describe("createBreadcrumbSchema", () => {
{ name: "Current Page" },
]);
- expect(schema.itemListElement[0]!.item).toBe("https://cap.so");
+ expect(schema.itemListElement[0]?.item).toBe("https://cap.so");
expect("item" in schema.itemListElement[1]!).toBe(false);
});
@@ -55,7 +55,7 @@ describe("createBreadcrumbSchema", () => {
]);
expect(schema.itemListElement).toHaveLength(1);
- expect(schema.itemListElement[0]!.position).toBe(1);
+ expect(schema.itemListElement[0]?.position).toBe(1);
});
it("handles empty array", () => {
diff --git a/apps/web/__tests__/unit/developer-actions.test.ts b/apps/web/__tests__/unit/developer-actions.test.ts
index ed320e0d4..4616b1842 100644
--- a/apps/web/__tests__/unit/developer-actions.test.ts
+++ b/apps/web/__tests__/unit/developer-actions.test.ts
@@ -181,7 +181,7 @@ describe("createDeveloperApp", () => {
});
expect(mockDb.insert).toHaveBeenCalled();
- const firstValuesCall = mockDb.values.mock.calls[0]![0];
+ const firstValuesCall = mockDb.values.mock.calls[0]?.[0];
expect(firstValuesCall).toMatchObject({
name: "My App",
environment: "production",
@@ -238,7 +238,7 @@ describe("createDeveloperApp", () => {
});
const expectedPrefix = result.publicKey.slice(0, 12);
- const keysValuesCall = mockDb.values.mock.calls[1]![0];
+ const keysValuesCall = mockDb.values.mock.calls[1]?.[0];
const publicKeyEntry = keysValuesCall.find(
(entry: Record<string, unknown>) => entry.keyType === "public",
);
diff --git a/apps/web/__tests__/unit/developer-documentation-videos-page.test.ts b/apps/web/__tests__/unit/developer-documentation-videos-page.test.ts
index 4b824aa39..772d5da75 100644
--- a/apps/web/__tests__/unit/developer-documentation-videos-page.test.ts
+++ b/apps/web/__tests__/unit/developer-documentation-videos-page.test.ts
@@ -160,7 +160,7 @@ describe("DeveloperDocumentationVideosPage FAQ schema", () => {
name: "What is a developer documentation video?",
acceptedAnswer: {
"@type": "Answer",
- text: faqs[0]!.answer,
+ text: faqs[0]?.answer,
},
});
});
diff --git a/apps/web/__tests__/unit/faq-schema.test.ts b/apps/web/__tests__/unit/faq-schema.test.ts
index c5ff0d4f6..c49e5b6ed 100644
--- a/apps/web/__tests__/unit/faq-schema.test.ts
+++ b/apps/web/__tests__/unit/faq-schema.test.ts
@@ -32,7 +32,7 @@ describe("createFAQSchema", () => {
text: "Yes, Cap is free.",
},
});
- expect(schema.mainEntity[1]!.name).toBe("What platforms does Cap support?");
+ expect(schema.mainEntity[1]?.name).toBe("What platforms does Cap support?");
expect(schema.mainEntity).toHaveLength(2);
});
@@ -46,10 +46,10 @@ describe("createFAQSchema", () => {
];
const schema = createFAQSchema(faqs);
- expect(schema.mainEntity[0]!.acceptedAnswer.text).toBe(
+ expect(schema.mainEntity[0]?.acceptedAnswer.text).toBe(
"Visit the download page to get started.",
);
- expect(schema.mainEntity[0]!.acceptedAnswer.text).not.toContain("<a");
+ expect(schema.mainEntity[0]?.acceptedAnswer.text).not.toContain("<a");
});
it("strips multiple different HTML tags", () => {
@@ -62,7 +62,7 @@ describe("createFAQSchema", () => {
];
const schema = createFAQSchema(faqs);
- expect(schema.mainEntity[0]!.acceptedAnswer.text).toBe(
+ expect(schema.mainEntity[0]?.acceptedAnswer.text).toBe(
"Cap offers 4K recording, instant sharing, and affordable pricing.",
);
});
@@ -127,8 +127,8 @@ describe("createFAQSchema", () => {
expect(schema["@type"]).toBe("FAQPage");
expect(schema.mainEntity).toHaveLength(5);
- expect(schema.mainEntity[3]!.acceptedAnswer.text).not.toContain("<a");
- expect(schema.mainEntity[3]!.acceptedAnswer.text).toContain("macOS");
+ expect(schema.mainEntity[3]?.acceptedAnswer.text).not.toContain("<a");
+ expect(schema.mainEntity[3]?.acceptedAnswer.text).toContain("macOS");
});
it("applies FAQPage schema to free-screen-recorder page FAQs", () => {
@@ -162,8 +162,8 @@ describe("createFAQSchema", () => {
expect(schema["@type"]).toBe("FAQPage");
expect(schema.mainEntity).toHaveLength(5);
- expect(schema.mainEntity[0]!.acceptedAnswer.text).not.toContain("<a");
- expect(schema.mainEntity[0]!.acceptedAnswer.text).toContain(
+ expect(schema.mainEntity[0]?.acceptedAnswer.text).not.toContain("<a");
+ expect(schema.mainEntity[0]?.acceptedAnswer.text).toContain(
"professional-grade",
);
});
diff --git a/apps/web/__tests__/unit/hipaa-compliant-screen-recording-page.test.ts b/apps/web/__tests__/unit/hipaa-compliant-screen-recording-page.test.ts
index 1b43c8a7c..c82a51f93 100644
--- a/apps/web/__tests__/unit/hipaa-compliant-screen-recording-page.test.ts
+++ b/apps/web/__tests__/unit/hipaa-compliant-screen-recording-page.test.ts
@@ -151,7 +151,7 @@ describe("HipaaCompliantScreenRecordingPage FAQ schema", () => {
name: "Can Cap be used for HIPAA-compliant screen recording?",
acceptedAnswer: {
"@type": "Answer",
- text: faqs[0]!.answer,
+ text: faqs[0]?.answer,
},
});
});
diff --git a/apps/web/__tests__/unit/howto-schema.test.ts b/apps/web/__tests__/unit/howto-schema.test.ts
index ac7ffda3f..9d48d5341 100644
--- a/apps/web/__tests__/unit/howto-schema.test.ts
+++ b/apps/web/__tests__/unit/howto-schema.test.ts
@@ -34,8 +34,8 @@ describe("createHowToSchema", () => {
name: "Download",
text: "Download the app.",
});
- expect(schema.step[1]!.position).toBe(2);
- expect(schema.step[2]!.position).toBe(3);
+ expect(schema.step[1]?.position).toBe(2);
+ expect(schema.step[2]?.position).toBe(3);
});
it("uses default totalTime of PT2M when not provided", () => {
@@ -124,7 +124,7 @@ describe("createHowToSchema", () => {
expect(schema["@type"]).toBe("HowTo");
expect(schema.step).toHaveLength(4);
- expect(schema.step[0]!.name).toBe("Download and install Cap");
- expect(schema.step[3]!.position).toBe(4);
+ expect(schema.step[0]?.name).toBe("Download and install Cap");
+ expect(schema.step[3]?.position).toBe(4);
});
});
diff --git a/apps/web/__tests__/unit/mac-screen-recording-with-audio-page.test.ts b/apps/web/__tests__/unit/mac-screen-recording-with-audio-page.test.ts
index 288df5271..6a4075c77 100644
--- a/apps/web/__tests__/unit/mac-screen-recording-with-audio-page.test.ts
+++ b/apps/web/__tests__/unit/mac-screen-recording-with-audio-page.test.ts
@@ -176,7 +176,7 @@ describe("MacScreenRecordingWithAudioPage FAQ schema", () => {
name: "Why doesn't macOS record internal audio by default?",
acceptedAnswer: {
"@type": "Answer",
- text: faqs[0]!.answer,
+ text: faqs[0]?.answer,
},
});
});
diff --git a/apps/web/__tests__/unit/mov-to-mp4-page.test.ts b/apps/web/__tests__/unit/mov-to-mp4-page.test.ts
index 6025972b7..7be75ecd0 100644
--- a/apps/web/__tests__/unit/mov-to-mp4-page.test.ts
+++ b/apps/web/__tests__/unit/mov-to-mp4-page.test.ts
@@ -114,7 +114,7 @@ describe("MOV to MP4 FAQ schema validity", () => {
name: "How do I convert MOV to MP4 online?",
acceptedAnswer: {
"@type": "Answer",
- text: faqs[0]!.answer,
+ text: faqs[0]?.answer,
},
});
});
@@ -164,11 +164,11 @@ describe("MOV to MP4 HowTo schema validity", () => {
steps: howToSteps,
});
- expect(schema.step[0]!.position).toBe(1);
- expect(schema.step[0]!.name).toBe("Upload your MOV file");
- expect(schema.step[1]!.position).toBe(2);
- expect(schema.step[2]!.position).toBe(3);
- expect(schema.step[2]!.name).toBe("Download your MP4");
+ expect(schema.step[0]?.position).toBe(1);
+ expect(schema.step[0]?.name).toBe("Upload your MOV file");
+ expect(schema.step[1]?.position).toBe(2);
+ expect(schema.step[2]?.position).toBe(3);
+ expect(schema.step[2]?.name).toBe("Download your MP4");
});
it("produces JSON-serializable output", () => {
diff --git a/apps/web/__tests__/unit/mp4-to-gif-page.test.ts b/apps/web/__tests__/unit/mp4-to-gif-page.test.ts
index b0f54ff77..a27066f31 100644
--- a/apps/web/__tests__/unit/mp4-to-gif-page.test.ts
+++ b/apps/web/__tests__/unit/mp4-to-gif-page.test.ts
@@ -114,7 +114,7 @@ describe("MP4 to GIF FAQ schema validity", () => {
name: "How do I convert MP4 to GIF?",
acceptedAnswer: {
"@type": "Answer",
- text: faqs[0]!.answer,
+ text: faqs[0]?.answer,
},
});
});
@@ -164,11 +164,11 @@ describe("MP4 to GIF HowTo schema validity", () => {
steps: howToSteps,
});
- expect(schema.step[0]!.position).toBe(1);
- expect(schema.step[0]!.name).toBe("Upload your MP4 file");
- expect(schema.step[1]!.position).toBe(2);
- expect(schema.step[2]!.position).toBe(3);
- expect(schema.step[2]!.name).toBe("Convert and download your GIF");
+ expect(schema.step[0]?.position).toBe(1);
+ expect(schema.step[0]?.name).toBe("Upload your MP4 file");
+ expect(schema.step[1]?.position).toBe(2);
+ expect(schema.step[2]?.position).toBe(3);
+ expect(schema.step[2]?.name).toBe("Convert and download your GIF");
});
it("produces JSON-serializable output", () => {
diff --git a/apps/web/__tests__/unit/obs-alternative-page.test.ts b/apps/web/__tests__/unit/obs-alternative-page.test.ts
index 30697d4d3..cee286d2c 100644
--- a/apps/web/__tests__/unit/obs-alternative-page.test.ts
+++ b/apps/web/__tests__/unit/obs-alternative-page.test.ts
@@ -153,7 +153,7 @@ describe("ObsAlternativePage FAQ schema", () => {
name: "Why would I use Cap instead of OBS Studio?",
acceptedAnswer: {
"@type": "Answer",
- text: faqs[0]!.answer,
+ text: faqs[0]?.answer,
},
});
});
diff --git a/apps/web/__tests__/unit/open-source-screen-recorder-page.test.ts b/apps/web/__tests__/unit/open-source-screen-recorder-page.test.ts
index 13c69b0ba..a1dde8388 100644
--- a/apps/web/__tests__/unit/open-source-screen-recorder-page.test.ts
+++ b/apps/web/__tests__/unit/open-source-screen-recorder-page.test.ts
@@ -149,7 +149,7 @@ describe("OpenSourceScreenRecorderPage FAQ schema", () => {
name: "Is Cap really open source?",
acceptedAnswer: {
"@type": "Answer",
- text: faqs[0]!.answer,
+ text: faqs[0]?.answer,
},
});
});
diff --git a/apps/web/__tests__/unit/self-hosted-screen-recording-page.test.ts b/apps/web/__tests__/unit/self-hosted-screen-recording-page.test.ts
index 0184435da..e9db417fe 100644
--- a/apps/web/__tests__/unit/self-hosted-screen-recording-page.test.ts
+++ b/apps/web/__tests__/unit/self-hosted-screen-recording-page.test.ts
@@ -152,7 +152,7 @@ describe("SelfHostedScreenRecordingPage FAQ schema", () => {
name: "Can Cap be self-hosted?",
acceptedAnswer: {
"@type": "Answer",
- text: faqs[0]!.answer,
+ text: faqs[0]?.answer,
},
});
});
diff --git a/apps/web/__tests__/unit/video-recording-software-page.test.ts b/apps/web/__tests__/unit/video-recording-software-page.test.ts
index 85d29d1b6..697c8b318 100644
--- a/apps/web/__tests__/unit/video-recording-software-page.test.ts
+++ b/apps/web/__tests__/unit/video-recording-software-page.test.ts
@@ -148,7 +148,7 @@ describe("VideoRecordingSoftwarePage FAQ schema", () => {
name: "What is video recording software?",
acceptedAnswer: {
"@type": "Answer",
- text: faqs[0]!.answer,
+ text: faqs[0]?.answer,
},
});
});
diff --git a/apps/web/__tests__/unit/video-speed-controller-page.test.ts b/apps/web/__tests__/unit/video-speed-controller-page.test.ts
index e11982c6b..d2765577b 100644
--- a/apps/web/__tests__/unit/video-speed-controller-page.test.ts
+++ b/apps/web/__tests__/unit/video-speed-controller-page.test.ts
@@ -114,7 +114,7 @@ describe("Video Speed Controller FAQ schema validity", () => {
name: "How do I change the speed of a video online?",
acceptedAnswer: {
"@type": "Answer",
- text: faqs[0]!.answer,
+ text: faqs[0]?.answer,
},
});
});
@@ -164,11 +164,11 @@ describe("Video Speed Controller HowTo schema validity", () => {
steps: howToSteps,
});
- expect(schema.step[0]!.position).toBe(1);
- expect(schema.step[0]!.name).toBe("Upload your video file");
- expect(schema.step[1]!.position).toBe(2);
- expect(schema.step[2]!.position).toBe(3);
- expect(schema.step[2]!.name).toBe("Process and download your video");
+ expect(schema.step[0]?.position).toBe(1);
+ expect(schema.step[0]?.name).toBe("Upload your video file");
+ expect(schema.step[1]?.position).toBe(2);
+ expect(schema.step[2]?.position).toBe(3);
+ expect(schema.step[2]?.name).toBe("Process and download your video");
});
it("produces JSON-serializable output", () => {
diff --git a/apps/web/__tests__/unit/videos-policy.test.ts b/apps/web/__tests__/unit/videos-policy.test.ts
index 9dca40b7a..2e4d0a71a 100644
--- a/apps/web/__tests__/unit/videos-policy.test.ts
+++ b/apps/web/__tests__/unit/videos-policy.test.ts
@@ -5,7 +5,7 @@ import {
type User,
Video,
} from "@cap/web-domain";
-import { Context, Effect, Option } from "effect";
+import { Effect, Option } from "effect";
import { describe, expect, it } from "vitest";
const TEST_VIDEO_ID = "test-video-1" as Video.VideoId;
diff --git a/apps/web/__tests__/unit/webm-to-mp4-page.test.ts b/apps/web/__tests__/unit/webm-to-mp4-page.test.ts
index e76be34f9..8f30523dd 100644
--- a/apps/web/__tests__/unit/webm-to-mp4-page.test.ts
+++ b/apps/web/__tests__/unit/webm-to-mp4-page.test.ts
@@ -119,7 +119,7 @@ describe("WebM to MP4 FAQ schema validity", () => {
name: "How do I convert WebM to MP4 online?",
acceptedAnswer: {
"@type": "Answer",
- text: faqs[0]!.answer,
+ text: faqs[0]?.answer,
},
});
});
@@ -169,11 +169,11 @@ describe("WebM to MP4 HowTo schema validity", () => {
steps: howToSteps,
});
- expect(schema.step[0]!.position).toBe(1);
- expect(schema.step[0]!.name).toBe("Upload your WebM file");
- expect(schema.step[1]!.position).toBe(2);
- expect(schema.step[2]!.position).toBe(3);
- expect(schema.step[2]!.name).toBe("Download your MP4");
+ expect(schema.step[0]?.position).toBe(1);
+ expect(schema.step[0]?.name).toBe("Upload your WebM file");
+ expect(schema.step[1]?.position).toBe(2);
+ expect(schema.step[2]?.position).toBe(3);
+ expect(schema.step[2]?.name).toBe("Download your MP4");
});
it("produces JSON-serializable output", () => {