From 56bd7324e11174eee165a608666b0b5fe5babf41 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Thu, 23 Jun 2022 11:31:25 -0500 Subject: [PATCH] Write tests for common.ts --- tests/example.test.ts | 6 ------ tests/util/common.test.ts | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) delete mode 100644 tests/example.test.ts create mode 100644 tests/util/common.test.ts diff --git a/tests/example.test.ts b/tests/example.test.ts deleted file mode 100644 index d02541a..0000000 --- a/tests/example.test.ts +++ /dev/null @@ -1,6 +0,0 @@ -import Decimal from "util/bignum"; - -test("Decimals?", () => { - const x = new Decimal(3); - expect(x.m).toBe(3); -}); diff --git a/tests/util/common.test.ts b/tests/util/common.test.ts new file mode 100644 index 0000000..134a84a --- /dev/null +++ b/tests/util/common.test.ts @@ -0,0 +1,25 @@ +import { jest, describe, expect, test } from "@jest/globals"; +import { camelToTitle, isFunction } from "util/common"; + +describe("camelToTitle", () => { + test("Capitalizes first letter in single word", () => + expect(camelToTitle("test")).toBe("Test")); + + test("Converts three word camel case string to title case", () => + expect(camelToTitle("camelCaseTest")).toBe("Camel Case Test")); +}); + +describe("isFunction", () => { + test("Given function returns true", () => expect(isFunction(jest.fn())).toBe(true)); + + // Go through all primitives and basic types + test("Given a string returns false", () => expect(isFunction("test")).toBe(false)); + test("Given a number returns false", () => expect(isFunction(10)).toBe(false)); + test("Given a bigint returns false", () => expect(isFunction(BigInt(10))).toBe(false)); + test("Given a boolean returns false", () => expect(isFunction(true)).toBe(false)); + test("Given undefined returns false", () => expect(isFunction(undefined)).toBe(false)); + test("Given a symbol returns false", () => expect(isFunction(Symbol())).toBe(false)); + test("Given null returns false", () => expect(isFunction(null)).toBe(false)); + test("Given object returns false", () => expect(isFunction({})).toBe(false)); + test("Given array returns false", () => expect(isFunction([])).toBe(false)); +});