@@ -12,9 +12,88 @@ describe("isCreditCardValid", () => {
1212 expect ( result ) . toBe ( false ) ;
1313 } ) ;
1414
15+ it ( "should return false when the length of the input is less than 13" , ( ) => {
16+ const result = isCreditCardValid ( "123456781234" ) ;
17+ expect ( result ) . toBe ( false ) ;
18+ } ) ;
19+
20+ it ( "should return false when the length of the input is greater than 19" , ( ) => {
21+ const result = isCreditCardValid ( "12345678123456781234" ) ;
22+ expect ( result ) . toBe ( false ) ;
23+ } ) ;
24+
1525 it ( "should throw an error when the input is not a string" , ( ) => {
1626 expect ( ( ) => isCreditCardValid ( 1234567812345678 as any ) ) . toThrow (
1727 "The input should be a string." ,
1828 ) ;
1929 } ) ;
30+
31+ it ( "should return false when the input is an empty string" , ( ) => {
32+ const result = isCreditCardValid ( "" ) ;
33+ expect ( result ) . toBe ( false ) ;
34+ } ) ;
35+
36+ it ( "should return false when the input is a string with only spaces" , ( ) => {
37+ const result = isCreditCardValid ( " " ) ;
38+ expect ( result ) . toBe ( false ) ;
39+ } ) ;
40+
41+ it ( "should return false when the input is a string with only letters" , ( ) => {
42+ const result = isCreditCardValid ( "abcdefgh" ) ;
43+ const result2 = isCreditCardValid ( "asdfghjklcmvnshdg==" ) ;
44+ const result3 = isCreditCardValid ( "asdfghjklcmvnshdg" ) ;
45+ expect ( result ) . toBe ( false ) ;
46+ expect ( result2 ) . toBe ( false ) ;
47+ expect ( result3 ) . toBe ( false ) ;
48+ } ) ;
49+
50+ it ( "should return false when having a letter in the middle of the string" , ( ) => {
51+ const result = isCreditCardValid ( "1234a5678" ) ;
52+ expect ( result ) . toBe ( false ) ;
53+ } ) ;
54+
55+ it ( "should return false when the input is a string with only special characters" , ( ) => {
56+ const result = isCreditCardValid ( "++++" ) ;
57+ expect ( result ) . toBe ( false ) ;
58+ } ) ;
59+
60+ it ( "should return false when the input is a string with only special characters and numbers" , ( ) => {
61+ const result = isCreditCardValid ( "1234++++" ) ;
62+ expect ( result ) . toBe ( false ) ;
63+ } ) ;
64+
65+ it ( "should return false when the input is a string with only special characters and letters" , ( ) => {
66+ const result = isCreditCardValid ( "abcd++++" ) ;
67+ expect ( result ) . toBe ( false ) ;
68+ } ) ;
69+
70+ it ( "should return false when the input is a string with only special characters, letters and numbers" , ( ) => {
71+ const result = isCreditCardValid ( "abcd1234++++" ) ;
72+ expect ( result ) . toBe ( false ) ;
73+ } ) ;
74+
75+ it ( "should return false when the input is a string with only special characters and spaces" , ( ) => {
76+ const result = isCreditCardValid ( " ++++" ) ;
77+ expect ( result ) . toBe ( false ) ;
78+ } ) ;
79+
80+ it ( "should return false when the input is a string with only special characters, spaces and numbers" , ( ) => {
81+ const result = isCreditCardValid ( "1234 ++++" ) ;
82+ expect ( result ) . toBe ( false ) ;
83+ } ) ;
84+
85+ it ( "should return false when the input is a string with only special characters, spaces and letters" , ( ) => {
86+ const result = isCreditCardValid ( "abcd ++++" ) ;
87+ expect ( result ) . toBe ( false ) ;
88+ } ) ;
89+
90+ it ( "should return false when the input is a string with only special characters, spaces, letters and numbers" , ( ) => {
91+ const result = isCreditCardValid ( "abcd1234 ++++" ) ;
92+ expect ( result ) . toBe ( false ) ;
93+ } ) ;
94+
95+ it ( "should return false when the input is a string with only spaces and letters" , ( ) => {
96+ const result = isCreditCardValid ( " abcd" ) ;
97+ expect ( result ) . toBe ( false ) ;
98+ } ) ;
2099} ) ;
0 commit comments