Skip to content

Commit

Permalink
fix: fix missing noDataValue parameter
Browse files Browse the repository at this point in the history
getMetricByValue was missing noDataValue parameter,
but the description showed it had the parameter.
  • Loading branch information
ZuperZee committed Feb 1, 2021
1 parent 6e31740 commit 2d74d20
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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<number>,
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 };

0 comments on commit 2d74d20

Please sign in to comment.