From 4b25bfbc8a603d528e6bf2c3da3bad848e682a46 Mon Sep 17 00:00:00 2001 From: guerler Date: Mon, 7 Oct 2024 08:15:14 +0300 Subject: [PATCH] Add boolean conversion test case --- src/utilities/getFileName.test.js | 6 +++--- src/utilities/toBoolean.js | 2 +- src/utilities/toBoolean.test.js | 12 ++++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 src/utilities/toBoolean.test.js diff --git a/src/utilities/getFileName.test.js b/src/utilities/getFileName.test.js index 8b4a030..84cc16e 100644 --- a/src/utilities/getFileName.test.js +++ b/src/utilities/getFileName.test.js @@ -1,8 +1,8 @@ import { getFileName } from "./getFileName.js"; test("identify name without extension", () => { - expect(getFileName("name.extension")).toContain("name"); + expect(getFileName("name.extension")).toEqual("name"); expect(getFileName("/sub/path/name.extension")).toEqual("name"); - expect(getFileName("http://name.extension")).toContain("name"); - expect(getFileName("http://sub/path/name.extension")).toContain("name"); + expect(getFileName("http://name.extension")).toEqual("name"); + expect(getFileName("http://sub/path/name.extension")).toEqual("name"); }); diff --git a/src/utilities/toBoolean.js b/src/utilities/toBoolean.js index 3f1236e..acd55eb 100644 --- a/src/utilities/toBoolean.js +++ b/src/utilities/toBoolean.js @@ -1,3 +1,3 @@ export function toBoolean(value) { - return String(value) === "true"; + return String(value).toLowerCase() === "true"; } diff --git a/src/utilities/toBoolean.test.js b/src/utilities/toBoolean.test.js new file mode 100644 index 0000000..622d4a7 --- /dev/null +++ b/src/utilities/toBoolean.test.js @@ -0,0 +1,12 @@ +import { toBoolean } from "./toBoolean.js"; + +test("to boolean conversion", () => { + expect(toBoolean(true)).toBeTruthy(); + expect(toBoolean("true")).toBeTruthy(); + expect(toBoolean("TrUe")).toBeTruthy(); + expect(toBoolean(false)).toBeFalsy(); + expect(toBoolean("rue")).toBeFalsy(); + expect(toBoolean(1)).toBeFalsy(); + expect(toBoolean(null)).toBeFalsy(); + expect(toBoolean(undefined)).toBeFalsy(); +});