1- import { isValid , VALID_AREA_CODES , PHONE_MIN_LENGTH , PHONE_MAX_LENGTH } from '.' ;
1+ import {
2+ isValid ,
3+ isValidMobilePhone ,
4+ isValidLandlinePhone ,
5+ VALID_AREA_CODES ,
6+ PHONE_MIN_LENGTH ,
7+ PHONE_MAX_LENGTH ,
8+ } from '.' ;
29
310describe ( 'isValid' , ( ) => {
411 describe ( 'should return false' , ( ) => {
512 test ( 'when is a empty string' , ( ) => {
613 expect ( isValid ( '' ) ) . toBe ( false ) ;
14+ expect ( isValidMobilePhone ( '' ) ) . toBe ( false ) ;
15+ expect ( isValidLandlinePhone ( '' ) ) . toBe ( false ) ;
716 } ) ;
817
918 test ( 'when is null' , ( ) => {
1019 expect ( isValid ( null as any ) ) . toBe ( false ) ;
20+ expect ( isValidMobilePhone ( null as any ) ) . toBe ( false ) ;
21+ expect ( isValidLandlinePhone ( null as any ) ) . toBe ( false ) ;
1122 } ) ;
1223
1324 test ( 'when is undefined' , ( ) => {
1425 expect ( isValid ( undefined as any ) ) . toBe ( false ) ;
26+ expect ( isValidMobilePhone ( undefined as any ) ) . toBe ( false ) ;
27+ expect ( isValidLandlinePhone ( undefined as any ) ) . toBe ( false ) ;
1528 } ) ;
1629
1730 test ( 'when is a boolean' , ( ) => {
1831 expect ( isValid ( true as any ) ) . toBe ( false ) ;
1932 expect ( isValid ( false as any ) ) . toBe ( false ) ;
33+ expect ( isValidMobilePhone ( false as any ) ) . toBe ( false ) ;
34+ expect ( isValidLandlinePhone ( true as any ) ) . toBe ( false ) ;
35+ expect ( isValidMobilePhone ( false as any ) ) . toBe ( false ) ;
36+ expect ( isValidLandlinePhone ( true as any ) ) . toBe ( false ) ;
2037 } ) ;
2138
2239 test ( 'when is a object' , ( ) => {
2340 expect ( isValid ( { } as any ) ) . toBe ( false ) ;
41+ expect ( isValidMobilePhone ( { } as any ) ) . toBe ( false ) ;
42+ expect ( isValidLandlinePhone ( { } as any ) ) . toBe ( false ) ;
2443 } ) ;
2544
2645 test ( 'when is a array' , ( ) => {
2746 expect ( isValid ( [ ] as any ) ) . toBe ( false ) ;
47+ expect ( isValidMobilePhone ( [ ] as any ) ) . toBe ( false ) ;
48+ expect ( isValidLandlinePhone ( [ ] as any ) ) . toBe ( false ) ;
2849 } ) ;
2950
3051 test ( 'when is a mobile phone with mask and code state invalid' , ( ) => {
3152 expect ( isValid ( '(00) 3 0000-0000' ) ) . toBe ( false ) ;
53+ expect ( isValidMobilePhone ( '(00) 3 0000-0000' ) ) . toBe ( false ) ;
3254 } ) ;
3355
3456 test ( 'when is a landline with mask and code state invalid' , ( ) => {
3557 expect ( isValid ( '(11) 9000-0000' ) ) . toBe ( false ) ;
58+ expect ( isValidLandlinePhone ( '(11) 9000-0000' ) ) . toBe ( false ) ;
3659 } ) ;
3760
3861 test ( 'when is a mobile phone invalid with mask' , ( ) => {
3962 expect ( isValid ( '(11) 3 0000-0000' ) ) . toBe ( false ) ;
63+ expect ( isValidMobilePhone ( '(11) 3 0000-0000' ) ) . toBe ( false ) ;
4064 } ) ;
4165
4266 test ( 'when is a landline invalid with mask' , ( ) => {
4367 expect ( isValid ( '(11) 9000-0000' ) ) . toBe ( false ) ;
68+ expect ( isValidLandlinePhone ( '(11) 9000-0000' ) ) . toBe ( false ) ;
4469 } ) ;
4570
4671 test ( `when dont match with phone min length (${ PHONE_MIN_LENGTH } )` , ( ) => {
4772 expect ( isValid ( '11' ) ) . toBe ( false ) ;
73+ expect ( isValidMobilePhone ( '11' ) ) . toBe ( false ) ;
74+ expect ( isValidLandlinePhone ( '11' ) ) . toBe ( false ) ;
4875 } ) ;
4976
5077 test ( `when dont match with phone max length (${ PHONE_MAX_LENGTH } )` , ( ) => {
5178 expect ( isValid ( '11300000001130000000' ) ) . toBe ( false ) ;
79+ expect ( isValidMobilePhone ( '11300000001130000000' ) ) . toBe ( false ) ;
80+ expect ( isValidLandlinePhone ( '11300000001130000000' ) ) . toBe ( false ) ;
5281 } ) ;
5382 } ) ;
5483
@@ -59,18 +88,22 @@ describe('isValid', () => {
5988
6089 test ( 'when is a mobile phone valid with mask' , ( ) => {
6190 expect ( isValid ( '(11) 9 0000-0000' ) ) . toBe ( true ) ;
91+ expect ( isValidMobilePhone ( '(11) 9 0000-0000' ) ) . toBe ( true ) ;
6292 } ) ;
6393
6494 test ( 'when is a landline valid with mask' , ( ) => {
6595 expect ( isValid ( '(11) 3000-0000' ) ) . toBe ( true ) ;
96+ expect ( isValidLandlinePhone ( '(11) 3000-0000' ) ) . toBe ( true ) ;
6697 } ) ;
6798
6899 test ( 'when is a mobile phone valid without mask' , ( ) => {
69100 expect ( isValid ( '11900000000' ) ) . toBe ( true ) ;
101+ expect ( isValidMobilePhone ( '11900000000' ) ) . toBe ( true ) ;
70102 } ) ;
71103
72104 test ( 'when is a landline valid without mask' , ( ) => {
73105 expect ( isValid ( '1130000000' ) ) . toBe ( true ) ;
106+ expect ( isValidLandlinePhone ( '1130000000' ) ) . toBe ( true ) ;
74107 } ) ;
75108 } ) ;
76109} ) ;
0 commit comments