From ca7b5dba1ae91d0b2f3fa4103d0bc73b268b5fcd Mon Sep 17 00:00:00 2001 From: Alex Forsyth Date: Wed, 23 Dec 2020 17:56:58 -0500 Subject: [PATCH] fix: waiter validation throws a proper error object --- packages/util-waiter/src/utils/validate.spec.ts | 14 +++++++------- packages/util-waiter/src/utils/validate.ts | 14 +++++++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/util-waiter/src/utils/validate.spec.ts b/packages/util-waiter/src/utils/validate.spec.ts index e8bd7e335447..bff31c85656b 100644 --- a/packages/util-waiter/src/utils/validate.spec.ts +++ b/packages/util-waiter/src/utils/validate.spec.ts @@ -34,8 +34,8 @@ describe(validateWaiterOptions.name, () => { validateWaiterOptions(waiterOptions); expect(1).toBe("SHOULD NOT GET HERE"); } catch (e) { - expect(e).toBe( - "WaiterConfiguration.maxDelay [120] must be greater than WaiterConfiguration.minDelay [200] for this waiter" + expect(e.toString()).toBe( + "Error: WaiterConfiguration.maxDelay [120] must be greater than WaiterConfiguration.minDelay [200] for this waiter" ); done(); } @@ -59,7 +59,7 @@ describe(validateWaiterOptions.name, () => { try { validateWaiterOptions(waiterOptions); } catch (e) { - expect(e).toBe("WaiterConfiguration.maxWaitTime must be greater than 0"); + expect(e.toString()).toBe("Error: WaiterConfiguration.maxWaitTime must be greater than 0"); done(); } }); @@ -70,8 +70,8 @@ describe(validateWaiterOptions.name, () => { try { validateWaiterOptions(waiterOptions); } catch (e) { - expect(e).toBe( - "WaiterConfiguration.maxWaitTime [150] must be greater than WaiterConfiguration.minDelay [200] for this waiter" + expect(e.toString()).toBe( + "Error: WaiterConfiguration.maxWaitTime [150] must be greater than WaiterConfiguration.minDelay [200] for this waiter" ); done(); } @@ -83,8 +83,8 @@ describe(validateWaiterOptions.name, () => { try { validateWaiterOptions(waiterOptions); } catch (e) { - expect(e).toBe( - "WaiterConfiguration.maxWaitTime [200] must be greater than WaiterConfiguration.minDelay [200] for this waiter" + expect(e.toString()).toBe( + "Error: WaiterConfiguration.maxWaitTime [200] must be greater than WaiterConfiguration.minDelay [200] for this waiter" ); } }); diff --git a/packages/util-waiter/src/utils/validate.ts b/packages/util-waiter/src/utils/validate.ts index 49644886e3dd..c186d67fe38c 100644 --- a/packages/util-waiter/src/utils/validate.ts +++ b/packages/util-waiter/src/utils/validate.ts @@ -6,14 +6,18 @@ import { WaiterOptions } from "../waiter"; */ export const validateWaiterOptions = (options: WaiterOptions): void => { if (options.maxWaitTime < 1) { - throw `WaiterConfiguration.maxWaitTime must be greater than 0`; + throw new Error(`WaiterConfiguration.maxWaitTime must be greater than 0`); } else if (options.minDelay < 1) { - throw `WaiterConfiguration.minDelay must be greater than 0`; + throw new Error(`WaiterConfiguration.minDelay must be greater than 0`); } else if (options.maxDelay < 1) { - throw `WaiterConfiguration.maxDelay must be greater than 0`; + throw new Error(`WaiterConfiguration.maxDelay must be greater than 0`); } else if (options.maxWaitTime <= options.minDelay) { - throw `WaiterConfiguration.maxWaitTime [${options.maxWaitTime}] must be greater than WaiterConfiguration.minDelay [${options.minDelay}] for this waiter`; + throw new Error( + `WaiterConfiguration.maxWaitTime [${options.maxWaitTime}] must be greater than WaiterConfiguration.minDelay [${options.minDelay}] for this waiter` + ); } else if (options.maxDelay < options.minDelay) { - throw `WaiterConfiguration.maxDelay [${options.maxDelay}] must be greater than WaiterConfiguration.minDelay [${options.minDelay}] for this waiter`; + throw new Error( + `WaiterConfiguration.maxDelay [${options.maxDelay}] must be greater than WaiterConfiguration.minDelay [${options.minDelay}] for this waiter` + ); } };