@@ -5,20 +5,19 @@ import * as se from './se';
55describe ( 'no' , ( ) => {
66 test . each ( [
77 [ '0179' , true ] ,
8-
98 [ '01790' , false ] ,
109 [ 'not a number' , false ] ,
11- ] ) ( 'validatePostalCode() ' , ( input , expected ) => {
10+ ] ) ( 'validatePostalCode(%s) -> %s ' , ( input , expected ) => {
1211 expect ( no . validatePostalCode ( input ) ) . toBe ( expected ) ;
1312 } ) ;
1413
1514 test . each ( [
16- [ '22865500' , true ] ,
17- [ '90000000' , true ] ,
18- [ '40000000' , true ] ,
19- [ '22 86 55 00' , false ] ,
20- [ '000' , false ] ,
21- [ '000000000' , false ] ,
15+ [ '22865500' , true , undefined ] ,
16+ [ '90000000' , true , undefined ] ,
17+ [ '40000000' , true , undefined ] ,
18+ [ '22 86 55 00' , false , undefined ] ,
19+ [ '000' , false , undefined ] ,
20+ [ '000000000' , false , undefined ] ,
2221
2322 // formatting
2423 [ '22 86 55 00' , false , { allowFormatting : false } ] ,
@@ -28,102 +27,65 @@ describe('no', () => {
2827 [ '22865500' , false , { mobileOnly : true } ] ,
2928 [ '90000000' , true , { mobileOnly : true } ] ,
3029 [ '40000000' , true , { mobileOnly : true } ] ,
31- ] ) ( 'validatePhoneNumber() ' , ( input , expected , options ) => {
30+ ] ) ( 'validatePhoneNumber(%s) -> %s ' , ( input , expected , options ) => {
3231 expect ( no . validatePhoneNumber ( input , options ) ) . toBe ( expected ) ;
3332 } ) ;
3433
3534 test . each ( [
36- [ '937052766' , true ] ,
37- [ '937 052 766' , false ] ,
38- [ '435256151' , false ] ,
39- [ 'not a number' , false ] ,
40- [ 'A37 052 766' , false ] ,
35+ [ '937052766' , true , undefined ] ,
36+ [ '937 052 766' , false , undefined ] ,
37+ [ '435256151' , false , undefined ] ,
38+ [ 'not a number' , false , undefined ] ,
39+ [ 'A37 052 766' , false , undefined ] ,
4140
4241 // formatting
4342 [ '937 052 766' , false , { allowFormatting : false } ] ,
4443 [ '937 052 766' , true , { allowFormatting : true } ] ,
45- ] ) ( 'validateOrganizationNumber() ' , ( input , expected ) => {
46- expect ( no . validateOrganizationNumber ( input ) ) . toBe ( expected ) ;
44+ ] ) ( 'validateOrganizationNumber(%s) -> %s ' , ( input , expected , options ) => {
45+ expect ( no . validateOrganizationNumber ( input , options ) ) . toBe ( expected ) ;
4746 } ) ;
4847} ) ;
4948
5049describe ( 'se' , ( ) => {
5150 test . each ( [
52- [ '00000' , true ] ,
53- [ '000 00' , true ] ,
51+ [ '00000' , true , undefined ] ,
52+ [ '000 00' , false , undefined ] ,
53+ [ 'not a number' , false , undefined ] ,
5454
55- // strictness
56- [ '000 00' , false , { strict : true } ] ,
57-
58- [ '00' , false ] ,
59- [ 'not a number' , false ] ,
60- ] ) ( 'validatePostalCode()' , ( input , expected ) => {
61- expect ( se . validatePostalCode ( input ) ) . toBe ( expected ) ;
55+ // formatting
56+ [ '000 00' , false , { allowFormatting : false } ] ,
57+ [ '000 00' , true , { allowFormatting : true } ] ,
58+ ] ) ( 'validatePostalCode(%s) -> %s' , ( input , expected , options ) => {
59+ expect ( se . validatePostalCode ( input , options ) ) . toBe ( expected ) ;
6260 } ) ;
6361
6462 test . each ( [
65- [ '22865500' , true ] ,
66- [ '22 86 55 00' , true ] ,
67- [ '90000000' , true ] ,
68- [ '40000000' , true ] ,
69- [ '000' , false ] ,
70- [ '000000000' , false ] ,
63+ [ '08123456' , true , undefined ] ,
64+ [ '0812345' , false , undefined ] ,
65+ [ '031123456' , true , undefined ] ,
66+ [ '030312345678' , false , undefined ] ,
7167
72- // strictness
73- [ '22 86 55 00' , false , { strict : true } ] ,
68+ // formatting
69+ [ '031-123 45' , true , { allowFormatting : true } ] ,
70+ [ '031-123 45' , false , { allowFormatting : false } ] ,
7471
7572 // mobile only
76- [ '22 86 55 00' , false , { mobileOnly : true } ] ,
77- [ '900 00 000' , true , { mobileOnly : true } ] ,
78- [ '400 00 000' , true , { mobileOnly : true } ] ,
79- ] ) ( 'validatePhoneNumber()' , ( input , expected , options ) => {
73+ [ '0701234567' , true , { mobileOnly : true } ] ,
74+ [ '031123456' , false , { mobileOnly : true } ] ,
75+ ] ) ( 'validatePhoneNumber(%s) -> %s' , ( input , expected , options ) => {
8076 expect ( se . validatePhoneNumber ( input , options ) ) . toBe ( expected ) ;
8177 } ) ;
8278
8379 test . each ( [
84- [ '937052766' , true ] ,
85- [ '937 052 766' , true ] ,
80+ [ '5592221054' , true , undefined ] ,
81+ [ '559222-1054' , false , undefined ] ,
82+ [ '559222105' , false , undefined ] ,
83+ [ '55922210546' , false , undefined ] ,
8684
87- [ 'A37 052 766' , false ] ,
88- [ '435 256 151 ' , false ] ,
89- [ 'not a number ' , false ] ,
90- ] ) ( 'validateOrganizationNumber() ' , ( input , expected ) => {
91- expect ( se . validateOrganizationNumber ( input ) ) . toBe ( expected ) ;
85+ // formatting
86+ [ '559222-1054 ' , false , { allowFormatting : false } ] ,
87+ [ '559222-1054 ' , true , { allowFormatting : true } ] ,
88+ ] ) ( 'validateOrganizationNumber(%s) -> %s ' , ( input , expected , options ) => {
89+ expect ( se . validateOrganizationNumber ( input , options ) ) . toBe ( expected ) ;
9290 } ) ;
9391} ) ;
94-
95- // describe('no', () => {
96- // describe('validatePostalCode', () => {
97- // test('correctly validates postal codes', () => {
98- // expect(validatePostalCodeSe('100 26')).toBeTruthy();
99- // expect(validatePostalCodeSe('10026')).toBeTruthy();
100-
101- // expect(validatePostalCodeSe('100426')).toBeFalsy();
102- // expect(validatePostalCodeSe('177')).toBeFalsy();
103- // expect(validatePostalCodeSe(Number.NaN.toString())).toBeFalsy();
104- // expect(validatePostalCodeSe('not a number')).toBeFalsy();
105- // });
106- // });
107-
108- // describe('validatePhoneNumber()', () => {
109- // test('validates phone numbers', () => {
110- // // should be 8 to 10 digits
111- // expect(validatePhoneNumberSe('08123456')).toBeTruthy();
112- // expect(validatePhoneNumberSe('031123456')).toBeTruthy();
113- // expect(validatePhoneNumberSe('0311234567')).toBeTruthy();
114-
115- // // too short
116- // expect(validatePhoneNumberSe('0812345')).toBeFalsy();
117- // // too long
118- // expect(validatePhoneNumberSe('0303123456789')).toBeFalsy();
119-
120- // // cannot start with something other than 0
121- // expect(validatePhoneNumberSe('12345678')).toBeFalsy();
122-
123- // // A Swedish mobile number is always 10 digits and starts with 07
124- // expect(
125- // validatePhoneNumberSe('0712345678', { mobileOnly: true }),
126- // ).toBeTruthy();
127- // });
128- // });
129- // });
0 commit comments