From 2d74d2079d3d934e818f287e30024b62e5eed6be Mon Sep 17 00:00:00 2001 From: ZuperZee Date: Mon, 1 Feb 2021 14:03:34 +0100 Subject: [PATCH] fix: fix missing noDataValue parameter getMetricByValue was missing noDataValue parameter, but the description showed it had the parameter. --- src/index.test.ts | 10 ++++++++++ src/index.ts | 7 ++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index 367f8b7..3282907 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -63,6 +63,16 @@ describe("getMetricValue", () => { expect(getMetricValue("test", true)).toEqual(500); expect(getMetricValue("test", true, [0, 10], 2)).toEqual(5); }); + + it("returns noDataValue when no value is found", () => { + expect(getMetricValue("nonExistentName")).toBe(null); + expect( + getMetricValue("nonExistentName", false, [0, 100], 2, "something") + ).toBe("something"); + expect(getMetricValue("minimal", false, [0, 100], 2, "something")).toBe( + "something" + ); + }); }); describe("getShowcaseMetricValue", () => { diff --git a/src/index.ts b/src/index.ts index 6ecf0e2..d24e858 100644 --- a/src/index.ts +++ b/src/index.ts @@ -71,19 +71,20 @@ const getMetricValueByName = ( * @param showcase - Decides if values are randomly generated. * @param range - Range of values to return. * @param decimals - Amount of decimals returned. - * @param noDataValue - Returns null if no data is found. + * @param noDataValue - Return value when no data is found. */ function getMetricValue( metric: string, showcase = false, range?: Array, - decimals?: number + decimals?: number, + noDataValue: unknown = null ): unknown { if (showcase) { return getShowcaseMetricValue({ range, decimals }); } - return getMetricValueByName(metric); + return getMetricValueByName(metric, { noDataValue }); } export { getMetricValue, getMetricValueByName, getShowcaseMetricValue };