Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/utils/normalizeAbsent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { normalizeOptionalFields, normalizeList } from "./normalizeAbsent";

type MockObject = {
name: string;
temperature?: string | null;
targetYear?: number | null;
targetType?: "absolute" | "intensity" | null;
abool?: boolean | null;
zero?: number | null;
empty?: string | null;
missing?: string;
temperature?: string | null | undefined;
targetYear?: number | null | undefined;
targetType?: "absolute" | "intensity" | null | undefined;
abool?: boolean | null | undefined;
zero?: number | null | undefined;
empty?: string | null | undefined;
missing?: string | undefined;
Comment on lines +7 to +13
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Adding | undefined to optional properties is redundant in TypeScript. The ? operator already includes undefined in the type union. For consistency and conciseness, consider removing the explicit | undefined from all optional property declarations (lines 7-13).

Suggested change
temperature?: string | null | undefined;
targetYear?: number | null | undefined;
targetType?: "absolute" | "intensity" | null | undefined;
abool?: boolean | null | undefined;
zero?: number | null | undefined;
empty?: string | null | undefined;
missing?: string | undefined;
temperature?: string | null;
targetYear?: number | null;
targetType?: "absolute" | "intensity" | null;
abool?: boolean | null;
zero?: number | null;
empty?: string | null;
missing?: string;

Copilot uses AI. Check for mistakes.
};

describe("normalizeOptionalFields", () => {
Expand Down Expand Up @@ -49,7 +49,6 @@ describe("normalizeOptionalFields", () => {
const n = normalizeOptionalFields(base, ["temperature"] as const);
expect(isAbsent(n.temperature)).toBe(true);
// not selected -> remains null
// @ts-expect-error - targetYear is still possibly null/undefined
expect(n.targetYear).toBeNull();
});
});
Expand All @@ -62,6 +61,8 @@ describe("normalizeList", () => {
{ name: "C" }, // missing
];
const out = normalizeList(list, ["temperature"] as const);
if (!out[0] || !out[1] || !out[2])
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runtime check uses truthiness evaluation (!out[0]) which would fail if the array element exists but has a falsy value (e.g., an object with only falsy properties). Consider using out.length !== 3 instead to check only the array length: if (out.length !== 3) throw new Error('Expected array to have 3 items');

Suggested change
if (!out[0] || !out[1] || !out[2])
if (out.length !== 3)

Copilot uses AI. Check for mistakes.
throw new Error("Expected array to have 3 items");
expect(isAbsent(out[0].temperature)).toBe(true);
expect(out[1].temperature).toBe("2°C");
expect(isAbsent(out[2].temperature)).toBe(true);
Expand Down