From 7fb685efff18a4073dbf226e292e4771204efec2 Mon Sep 17 00:00:00 2001 From: Ian Bull Date: Thu, 22 Aug 2024 01:35:34 -0400 Subject: [PATCH] refactor(internal): align additional error messages (#5766) --- internal/diff.ts | 4 +++- internal/diff_test.ts | 25 ++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/internal/diff.ts b/internal/diff.ts index fcf82202a..ad091d042 100644 --- a/internal/diff.ts +++ b/internal/diff.ts @@ -77,7 +77,9 @@ export function assertFp(value: unknown): asserts value is FarthestPoint { typeof (value as FarthestPoint)?.y !== "number" || typeof (value as FarthestPoint)?.id !== "number" ) { - throw new Error("Unexpected missing FarthestPoint"); + throw new Error( + `Unexpected value, expected 'FarthestPoint': received ${typeof value}`, + ); } } diff --git a/internal/diff_test.ts b/internal/diff_test.ts index d2f014a84..ab71b9d88 100644 --- a/internal/diff_test.ts +++ b/internal/diff_test.ts @@ -134,11 +134,26 @@ Deno.test({ Deno.test({ name: "assertFp() throws", fn() { - const error = "Unexpected missing FarthestPoint"; - assertThrows(() => assertFp({ id: 0 }), Error, error); - assertThrows(() => assertFp({ y: 0 }), Error, error); - assertThrows(() => assertFp(undefined), Error, error); - assertThrows(() => assertFp(null), Error, error); + assertThrows( + () => assertFp({ id: 0 }), + Error, + "Unexpected value, expected 'FarthestPoint': received object", + ); + 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", + ); }, });