Skip to content

Commit d5d16fa

Browse files
committed
adding tests for card number length validation and only digit
1 parent f0d7b15 commit d5d16fa

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Sprint-3/3-stretch/creditCard-validator.test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe("creditCardValidator", () => {
77
});
88

99
test("should return false if the card number is not digit only", () => {
10-
expect(creditCardValidator("1234-5678-9012-345a")).toBe(false);
10+
expect(creditCardValidator("1234-5678-abcd-3456")).toBe(false);
1111
expect(creditCardValidator("1234 5678 9012 3456")).toBe(true);
1212
});
1313

@@ -26,4 +26,16 @@ describe("creditCardValidator", () => {
2626
expect(creditCardValidator("1111 1111 1111 1111")).toBe(false);
2727
expect(creditCardValidator("1234 5678 9012 3456")).toBe(true);
2828
});
29+
30+
// test for less than 16 digits
31+
test("should return false for a card number with less than 16 digits", () => {
32+
expect(creditCardValidator("123456789012345")).toBe(false);
33+
expect(creditCardValidator("1234-5678-9012-345")).toBe(false);
34+
});
35+
36+
// test for more than 16 digits
37+
test("should return false for a card number with more than 16 digits", () => {
38+
expect(creditCardValidator("12345678901234567")).toBe(false);
39+
expect(creditCardValidator("1234-5678-9012-34567")).toBe(false);
40+
});
2941
});

0 commit comments

Comments
 (0)