|
1 | 1 | import { render, screen } from "@testing-library/svelte"; |
| 2 | +import type DataTableComponent from "carbon-components-svelte/DataTable/DataTable.svelte"; |
| 3 | +import type { ComponentEvents } from "svelte"; |
2 | 4 | import { tick } from "svelte"; |
3 | 5 | import { user } from "../setup-tests"; |
4 | 6 | import DataTable from "./DataTable.test.svelte"; |
@@ -1157,4 +1159,57 @@ describe("DataTable", () => { |
1157 | 1159 | expect(detail).toHaveProperty("currentTarget"); |
1158 | 1160 | expect(detail).toHaveProperty("row"); |
1159 | 1161 | }); |
| 1162 | + |
| 1163 | + // Regression test for issue https://github.com/carbon-design-system/carbon-components-svelte/issues/2344 |
| 1164 | + describe("TypeScript event type definitions", () => { |
| 1165 | + it("click:row event type includes target and currentTarget", () => { |
| 1166 | + type Events = ComponentEvents<DataTableComponent<(typeof rows)[number]>>; |
| 1167 | + type ClickRowEventType = Events["click:row"]; |
| 1168 | + type ClickRowEvent = ClickRowEventType extends CustomEvent<infer T> |
| 1169 | + ? T |
| 1170 | + : never; |
| 1171 | + |
| 1172 | + expectTypeOf<ClickRowEvent>().toHaveProperty("row"); |
| 1173 | + expectTypeOf<ClickRowEvent>().toHaveProperty("target"); |
| 1174 | + expectTypeOf<ClickRowEvent>().toHaveProperty("currentTarget"); |
| 1175 | + expectTypeOf<ClickRowEvent["target"]>().toEqualTypeOf<EventTarget>(); |
| 1176 | + expectTypeOf< |
| 1177 | + ClickRowEvent["currentTarget"] |
| 1178 | + >().toEqualTypeOf<EventTarget>(); |
| 1179 | + }); |
| 1180 | + |
| 1181 | + it("click:cell event type includes target and currentTarget", () => { |
| 1182 | + type Events = ComponentEvents<DataTableComponent<(typeof rows)[number]>>; |
| 1183 | + type ClickCellEventType = Events["click:cell"]; |
| 1184 | + type ClickCellEvent = ClickCellEventType extends CustomEvent<infer T> |
| 1185 | + ? T |
| 1186 | + : never; |
| 1187 | + |
| 1188 | + expectTypeOf<ClickCellEvent>().toHaveProperty("cell"); |
| 1189 | + expectTypeOf<ClickCellEvent>().toHaveProperty("target"); |
| 1190 | + expectTypeOf<ClickCellEvent>().toHaveProperty("currentTarget"); |
| 1191 | + expectTypeOf<ClickCellEvent["target"]>().toEqualTypeOf<EventTarget>(); |
| 1192 | + expectTypeOf< |
| 1193 | + ClickCellEvent["currentTarget"] |
| 1194 | + >().toEqualTypeOf<EventTarget>(); |
| 1195 | + }); |
| 1196 | + |
| 1197 | + it("click:header event type includes target and currentTarget", () => { |
| 1198 | + type Events = ComponentEvents<DataTableComponent<(typeof rows)[number]>>; |
| 1199 | + type ClickHeaderEventType = Events["click:header"]; |
| 1200 | + type ClickHeaderEvent = ClickHeaderEventType extends CustomEvent<infer T> |
| 1201 | + ? T |
| 1202 | + : never; |
| 1203 | + |
| 1204 | + expectTypeOf<ClickHeaderEvent>().toHaveProperty("header"); |
| 1205 | + expectTypeOf<ClickHeaderEvent>().toHaveProperty("target"); |
| 1206 | + expectTypeOf<ClickHeaderEvent>().toHaveProperty("currentTarget"); |
| 1207 | + expectTypeOf<ClickHeaderEvent["target"]>().toEqualTypeOf<EventTarget>(); |
| 1208 | + expectTypeOf< |
| 1209 | + ClickHeaderEvent["currentTarget"] |
| 1210 | + >().toEqualTypeOf<EventTarget>(); |
| 1211 | + |
| 1212 | + expectTypeOf<ClickHeaderEvent>().toHaveProperty("sortDirection"); |
| 1213 | + }); |
| 1214 | + }); |
1160 | 1215 | }); |
0 commit comments