Skip to content

Commit

Permalink
test: added unit test for utils shouldPreventDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
keyurparalkar committed Oct 3, 2023
1 parent ed4d231 commit 51e3cc9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions package/lib/utils/utils.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});

0 comments on commit 51e3cc9

Please sign in to comment.