From 51e3cc9811ecba917410106758bef14892b5d060 Mon Sep 17 00:00:00 2001 From: keyurparalkar Date: Tue, 3 Oct 2023 11:36:32 +0530 Subject: [PATCH] test: added unit test for utils shouldPreventDefault --- package/lib/utils/utils.test.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 package/lib/utils/utils.test.ts diff --git a/package/lib/utils/utils.test.ts b/package/lib/utils/utils.test.ts new file mode 100644 index 0000000..acc589f --- /dev/null +++ b/package/lib/utils/utils.test.ts @@ -0,0 +1,31 @@ +import { shouldPreventDefault } from "./index"; + +describe("test shouldPreventDefault", () => { + test("1. Should return false if key that is pressed is: Ctrl + V, Backspace, and digits 1-9 when isAlphaNumeric = false", () => { + let key = "1"; + expect(shouldPreventDefault(key)).toBeFalsy(); + + key = "v"; + expect(shouldPreventDefault(key, false, true)).toBeFalsy(); + + key = "Backspace"; + expect(shouldPreventDefault(key)).toBeFalsy(); + + key = "a"; + expect(shouldPreventDefault(key)).toBeTruthy(); + }); + + test("2. Should return false if key that is pressed is: Ctrl + V, Backspace, and digits 1-9 when isAlphaNumeric = true", () => { + let key = "1"; + expect(shouldPreventDefault(key, true)).toBeFalsy(); + + key = "v"; // Ctrl + v + expect(shouldPreventDefault(key, true, true)).toBeFalsy(); + + key = "Backspace"; + expect(shouldPreventDefault(key, true)).toBeFalsy(); + + key = "a"; + expect(shouldPreventDefault(key, true)).toBeFalsy(); + }); +});