Skip to content

Commit 796f004

Browse files
authored
test: typecheck all source and test files (#2305)
1 parent e774974 commit 796f004

File tree

11 files changed

+121
-104
lines changed

11 files changed

+121
-104
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
],
3232
"scripts": {
3333
"test": "vitest",
34-
"test:src-types": "tsc types/**/*.ts",
34+
"test:src-types": "tsc",
3535
"test:types": "svelte-check --workspace tests",
3636
"lint": "biome check --write .",
3737
"build:css": "bun scripts/build-css",

tests/ComboBox/ComboBox.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { render, screen } from "@testing-library/svelte";
2+
import type { ComponentProps } from "svelte";
23
import { user } from "../setup-tests";
34
import ComboBox from "./ComboBox.test.svelte";
45
import ComboBoxCustom from "./ComboBoxCustom.test.svelte";
@@ -116,13 +117,14 @@ describe("ComboBox", () => {
116117
clearAll: "Remove all items",
117118
} as const;
118119

119-
render(ComboBox, {
120-
props: {
121-
selectedId: "1",
122-
value: "Email",
123-
translateWithIdSelection: (id) => customTranslations[id],
124-
},
125-
});
120+
const props = {
121+
selectedId: "1",
122+
value: "Email",
123+
translateWithIdSelection: (id: keyof typeof customTranslations) =>
124+
customTranslations[id],
125+
} satisfies ComponentProps<ComboBox>;
126+
127+
render(ComboBox, { props });
126128

127129
const clearButton = screen.getByRole("button", {
128130
name: "Remove selected item",

tests/DataTable/DataTableSearch.test.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { render, screen } from "@testing-library/svelte";
2+
import type { ComponentProps } from "svelte";
23
import { user } from "../setup-tests";
34
import DataTableSearch from "./DataTableSearch.test.svelte";
45

@@ -68,7 +69,7 @@ describe("DataTableSearch", () => {
6869
render(DataTableSearch, {
6970
props: {
7071
persistent: true,
71-
},
72+
} satisfies ComponentProps<DataTableSearch>,
7273
});
7374

7475
const searchBar = screen.getByRole("search");
@@ -152,16 +153,16 @@ describe("DataTableSearch", () => {
152153
});
153154

154155
it("can filter with a custom filter function", async () => {
155-
render(DataTableSearch, {
156-
props: {
157-
shouldFilterRows: (row, value) => {
158-
return (
159-
/(6|8)$/.test(row.name) &&
160-
row.rule.toLowerCase().includes(value.toString().toLowerCase())
161-
);
162-
},
156+
const props = {
157+
shouldFilterRows: (row: any, value: any) => {
158+
return (
159+
/(6|8)$/.test(row.name) &&
160+
row.rule.toLowerCase().includes(value.toString().toLowerCase())
161+
);
163162
},
164-
});
163+
} satisfies ComponentProps<DataTableSearch>;
164+
165+
render(DataTableSearch, { props });
165166

166167
allRowsRendered();
167168

tests/Dropdown/Dropdown.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ describe("Dropdown", () => {
2323
});
2424

2525
it("should handle custom item display text", () => {
26-
render(Dropdown, {
27-
props: {
28-
items,
29-
selectedId: "0",
30-
titleText: "Contact",
31-
itemToString: (item) => `${item.text} (${item.id})`,
32-
},
33-
});
26+
const props = {
27+
items,
28+
selectedId: "0",
29+
titleText: "Contact",
30+
itemToString: (item: (typeof items)[number]) =>
31+
`${item.text} (${item.id})`,
32+
};
33+
34+
render(Dropdown, { props });
3435

3536
const button = screen.getByRole("button");
3637
expect(button.querySelector(".bx--list-box__label")).toHaveTextContent(

tests/ListBox/ListBoxField.test.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { render, screen } from "@testing-library/svelte";
2+
import type { ComponentProps } from "svelte";
23
import { user } from "../setup-tests";
34
import ListBoxField from "./ListBoxField.test.svelte";
45

@@ -105,13 +106,14 @@ describe("ListBoxField", () => {
105106
close: "Custom close",
106107
} as const;
107108

108-
render(ListBoxField, {
109-
props: {
110-
"aria-expanded": false,
111-
translateWithId: (id) => customTranslations[id],
112-
slotContent: "Custom field",
113-
},
114-
});
109+
const props = {
110+
"aria-expanded": false,
111+
translateWithId: (id: keyof typeof customTranslations) =>
112+
customTranslations[id],
113+
slotContent: "Custom field",
114+
} satisfies ComponentProps<ListBoxField>;
115+
116+
render(ListBoxField, { props });
115117

116118
const field = screen
117119
.getByText("Custom field")
@@ -125,13 +127,14 @@ describe("ListBoxField", () => {
125127
close: "Custom close",
126128
} as const;
127129

128-
render(ListBoxField, {
129-
props: {
130-
"aria-expanded": true,
131-
translateWithId: (id) => customTranslations[id],
132-
slotContent: "Custom field",
133-
},
134-
});
130+
const props = {
131+
"aria-expanded": true,
132+
translateWithId: (id: keyof typeof customTranslations) =>
133+
customTranslations[id],
134+
slotContent: "Custom field",
135+
} satisfies ComponentProps<ListBoxField>;
136+
137+
render(ListBoxField, { props });
135138

136139
const field = screen
137140
.getByText("Custom field")

tests/ListBox/ListBoxMenuIcon.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { render } from "@testing-library/svelte";
2+
import type { ComponentProps } from "svelte";
23
import { user } from "../setup-tests";
34
import ListBoxMenuIcon from "./ListBoxMenuIcon.test.svelte";
45

@@ -51,12 +52,13 @@ describe("ListBoxMenuIcon", () => {
5152
close: "Custom close text",
5253
} as const;
5354

54-
const { component } = render(ListBoxMenuIcon, {
55-
props: {
56-
open: false,
57-
translateWithId: (id) => customTranslations[id],
58-
},
59-
});
55+
const props = {
56+
open: false,
57+
translateWithId: (id: keyof typeof customTranslations) =>
58+
customTranslations[id],
59+
} satisfies ComponentProps<ListBoxMenuIcon>;
60+
61+
const { component } = render(ListBoxMenuIcon, { props });
6062

6163
let svg = document.querySelector(".bx--list-box__menu-icon svg");
6264
expect(svg).toHaveAttribute("aria-label", "Custom open text");

tests/ListBox/ListBoxSelection.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { render, screen } from "@testing-library/svelte";
2+
import type { ComponentProps } from "svelte";
23
import { user } from "../setup-tests";
34
import ListBoxSelection from "./ListBoxSelection.test.svelte";
45

@@ -169,11 +170,12 @@ describe("ListBoxSelection", () => {
169170
clearAll: "Remove all",
170171
} as const;
171172

172-
const { component } = render(ListBoxSelection, {
173-
props: {
174-
translateWithId: (id) => customTranslations[id],
175-
},
176-
});
173+
const props = {
174+
translateWithId: (id: keyof typeof customTranslations) =>
175+
customTranslations[id],
176+
} satisfies ComponentProps<ListBoxSelection>;
177+
178+
const { component } = render(ListBoxSelection, { props });
177179

178180
const button = screen.getByRole("button");
179181
expect(button).toHaveAttribute("aria-label", "Remove item");

tests/MultiSelect/MultiSelect.test.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { render, screen } from "@testing-library/svelte";
2+
import type { MultiSelectItem } from "carbon-components-svelte/MultiSelect/MultiSelect.svelte";
3+
import type { ComponentProps } from "svelte";
24
import { user } from "../setup-tests";
35
import MultiSelect from "./MultiSelect.test.svelte";
46
import MultiSelectSlot from "./MultiSelectSlot.test.svelte";
@@ -167,15 +169,15 @@ describe("MultiSelect", () => {
167169

168170
it("uses custom filter function", async () => {
169171
const consoleLog = vi.spyOn(console, "log");
170-
render(MultiSelect, {
171-
props: {
172-
items,
173-
filterable: true,
174-
filterItem: (item, value) => {
175-
return item.text.toLowerCase().startsWith(value.toLowerCase());
176-
},
172+
const props = {
173+
items,
174+
filterable: true,
175+
filterItem: (item: MultiSelectItem, value: string) => {
176+
return item.text.toLowerCase().startsWith(value.toLowerCase());
177177
},
178-
});
178+
} satisfies ComponentProps<MultiSelect>;
179+
180+
render(MultiSelect, { props });
179181

180182
const input = screen.getByRole("combobox");
181183
await user.click(input);
@@ -492,27 +494,27 @@ describe("MultiSelect", () => {
492494

493495
describe("custom formatting", () => {
494496
it("handles custom itemToString", () => {
495-
render(MultiSelect, {
496-
props: {
497-
items,
498-
selectedIds: ["0"],
499-
itemToString: (item) => `${item.text} (${item.id})`,
500-
},
501-
});
497+
const props = {
498+
items,
499+
selectedIds: ["0"],
500+
itemToString: (item: MultiSelectItem) => `${item.text} (${item.id})`,
501+
} satisfies ComponentProps<MultiSelect>;
502+
503+
render(MultiSelect, { props });
502504

503505
expect(screen.getByText("Slack (0)")).toBeInTheDocument();
504506
});
505507

506508
it("handles custom itemToInput", async () => {
507-
render(MultiSelect, {
508-
props: {
509-
items,
510-
itemToInput: (item) => ({
511-
name: `contact_${item.id}`,
512-
value: item.text.toLowerCase(),
513-
}),
514-
},
515-
});
509+
const props = {
510+
items,
511+
itemToInput: (item: MultiSelectItem) => ({
512+
name: `contact_${item.id}`,
513+
value: item.text.toLowerCase(),
514+
}),
515+
} satisfies ComponentProps<MultiSelect>;
516+
517+
render(MultiSelect, { props });
516518

517519
await openMenu();
518520
const checkbox = screen.getByText("Slack");

tests/NumberInput/NumberInput.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { render, screen } from "@testing-library/svelte";
2+
import type { ComponentProps } from "svelte";
23
import { user } from "../setup-tests";
34
import NumberInput from "./NumberInput.test.svelte";
45
import NumberInputCustom from "./NumberInputCustom.test.svelte";
@@ -295,15 +296,15 @@ describe("NumberInput", () => {
295296
});
296297

297298
it("should support custom translateWithId function", () => {
298-
render(NumberInput, {
299-
props: {
300-
translateWithId: (id) => {
301-
if (id === "increment") return "Custom Increment";
302-
if (id === "decrement") return "Custom Decrement";
303-
return id;
304-
},
299+
const props = {
300+
translateWithId: (id: string) => {
301+
if (id === "increment") return "Custom Increment";
302+
if (id === "decrement") return "Custom Decrement";
303+
return id;
305304
},
306-
});
305+
} satisfies ComponentProps<NumberInput>;
306+
307+
render(NumberInput, { props });
307308

308309
expect(
309310
screen.getByRole("button", { name: "Custom Increment" }),

tests/Pagination/Pagination.test.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { render, screen, within } from "@testing-library/svelte";
2+
import type { ComponentProps } from "svelte";
23
import { user } from "../setup-tests";
34
import Pagination from "./Pagination.test.svelte";
45

@@ -225,35 +226,37 @@ describe("Pagination", () => {
225226
});
226227

227228
it("handles custom page text", () => {
228-
render(Pagination, {
229-
props: {
230-
pagesUnknown: true,
231-
totalItems: 100_000,
232-
pageText: (page) => `Current page ${page}`,
233-
},
234-
});
229+
const props = {
230+
pagesUnknown: true,
231+
totalItems: 100_000,
232+
pageText: (page: number) => `Current page ${page}`,
233+
} satisfies ComponentProps<Pagination>;
234+
235+
render(Pagination, { props });
235236

236237
expect(screen.getByText(/Current page 1/)).toBeInTheDocument();
237238
});
238239

239240
it("handles custom page range text", () => {
240-
render(Pagination, {
241-
props: {
242-
totalItems: 100_000,
243-
pageRangeText: (current, total) => `${current} of ${total}`,
244-
},
245-
});
241+
const props = {
242+
totalItems: 100_000,
243+
pageRangeText: (current: number, total: number) =>
244+
`${current} of ${total}`,
245+
} satisfies ComponentProps<Pagination>;
246+
247+
render(Pagination, { props });
246248

247249
expect(screen.getByText(/1 of 10000/)).toBeInTheDocument();
248250
});
249251

250252
it("handles custom item range text", () => {
251-
render(Pagination, {
252-
props: {
253-
totalItems: 100_000,
254-
itemRangeText: (min, max, total) => `${min}${max} of ${total}`,
255-
},
256-
});
253+
const props = {
254+
totalItems: 100_000,
255+
itemRangeText: (min: number, max: number, total: number) =>
256+
`${min}${max} of ${total}`,
257+
} satisfies ComponentProps<Pagination>;
258+
259+
render(Pagination, { props });
257260

258261
expect(screen.getByText(/110 of 100000/)).toBeInTheDocument();
259262
});

0 commit comments

Comments
 (0)