forked from AfterShip/phone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.spec.ts
53 lines (45 loc) · 1.08 KB
/
index.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import phone from '../src/index';
describe('Parameter types', () => {
test('using default parameter if not provided', () => {
const result = phone('+1 (817) 569-8900', {});
expect(result).toEqual({
isValid: true,
phoneNumber: '+18175698900',
countryIso2: 'US',
countryIso3: 'USA',
countryCode: '+1'
});
});
test('2nd parameter is undefined', () => {
const result = phone('+1 (817) 569-8900');
expect(result).toEqual({
isValid: true,
phoneNumber: '+18175698900',
countryIso2: 'US',
countryIso3: 'USA',
countryCode: '+1'
});
});
test('phone is not a string', () => {
const result = phone(18175698900 as unknown as string);
expect(result).toEqual({
isValid: false,
phoneNumber: null,
countryIso2: null,
countryIso3: null,
countryCode: null
});
});
test('country is not a string', () => {
const result = phone('+18175698900', {
country: 123 as unknown as string
});
expect(result).toEqual({
isValid: true,
phoneNumber: '+18175698900',
countryIso2: 'US',
countryIso3: 'USA',
countryCode: '+1'
});
});
});