refactor(internal): align additional error messages (#5766)

This commit is contained in:
Ian Bull 2024-08-22 01:35:34 -04:00 committed by GitHub
parent 8f3dd6ef0b
commit 7fb685efff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 6 deletions

View File

@ -77,7 +77,9 @@ export function assertFp(value: unknown): asserts value is FarthestPoint {
typeof (value as FarthestPoint)?.y !== "number" || typeof (value as FarthestPoint)?.y !== "number" ||
typeof (value as FarthestPoint)?.id !== "number" typeof (value as FarthestPoint)?.id !== "number"
) { ) {
throw new Error("Unexpected missing FarthestPoint"); throw new Error(
`Unexpected value, expected 'FarthestPoint': received ${typeof value}`,
);
} }
} }

View File

@ -134,11 +134,26 @@ Deno.test({
Deno.test({ Deno.test({
name: "assertFp() throws", name: "assertFp() throws",
fn() { fn() {
const error = "Unexpected missing FarthestPoint"; assertThrows(
assertThrows(() => assertFp({ id: 0 }), Error, error); () => assertFp({ id: 0 }),
assertThrows(() => assertFp({ y: 0 }), Error, error); Error,
assertThrows(() => assertFp(undefined), Error, error); "Unexpected value, expected 'FarthestPoint': received object",
assertThrows(() => assertFp(null), Error, error); );
assertThrows(
() => assertFp({ y: 0 }),
Error,
"Unexpected value, expected 'FarthestPoint': received object",
);
assertThrows(
() => assertFp(undefined),
Error,
"Unexpected value, expected 'FarthestPoint': received undefined",
);
assertThrows(
() => assertFp(null),
Error,
"Unexpected value, expected 'FarthestPoint': received object",
);
}, },
}); });