forked from olahol/iso-3166-2.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.spec.js
121 lines (105 loc) · 2.94 KB
/
functions.spec.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const iso3166 = require('./iso3166.min')
test('country()', () => {
expect(iso3166.country('SE'))
.toStrictEqual(expect.objectContaining({
code: 'SE',
name: 'Sweden'
}))
expect(iso3166.country('SWE'))
.toStrictEqual(expect.objectContaining({
code: 'SE',
name: 'Sweden'
}))
expect(iso3166.country('Sweden'))
.toStrictEqual(expect.objectContaining({
code: 'SE',
name: 'Sweden'
}))
expect(iso3166.country('UN')).toBe(null)
expect(iso3166.country('United Nations')).toBe(null)
})
test('subdivision()', () => {
expect(iso3166.subdivision('SE-O'))
.toStrictEqual(expect.objectContaining({
countryCode: 'SE',
countryName: 'Sweden',
code: 'SE-O',
regionCode: 'O',
name: 'Västra Götalands län'
}))
expect(iso3166.subdivision('SWE-O'))
.toStrictEqual(expect.objectContaining({
countryCode: 'SE',
countryName: 'Sweden',
code: 'SE-O',
regionCode: 'O',
name: 'Västra Götalands län'
}))
expect(iso3166.subdivision('SE', 'O'))
.toStrictEqual(expect.objectContaining({
countryCode: 'SE',
countryName: 'Sweden',
code: 'SE-O',
regionCode: 'O',
name: 'Västra Götalands län'
}))
expect(iso3166.subdivision('US-IN'))
.toStrictEqual(expect.objectContaining({
countryCode: 'US',
countryName: 'United States',
code: 'US-IN',
regionCode: 'IN',
name: 'Indiana'
}))
expect(iso3166.subdivision('US', 'IN'))
.toStrictEqual(expect.objectContaining({
countryCode: 'US',
countryName: 'United States',
code: 'US-IN',
regionCode: 'IN',
name: 'Indiana'
}))
expect(iso3166.subdivision('US-Indiana'))
.toStrictEqual(expect.objectContaining({
countryCode: 'US',
countryName: 'United States',
code: 'US-IN',
regionCode: 'IN',
name: 'Indiana'
}))
expect(iso3166.subdivision('USA-Indiana'))
.toStrictEqual(expect.objectContaining({
countryCode: 'US',
countryName: 'United States',
code: 'US-IN',
regionCode: 'IN',
name: 'Indiana'
}))
expect(iso3166.subdivision('US', 'Indiana'))
.toStrictEqual(expect.objectContaining({
countryCode: 'US',
countryName: 'United States',
code: 'US-IN',
regionCode: 'IN',
name: 'Indiana'
}))
expect(iso3166.subdivision('USA', 'Indiana'))
.toStrictEqual(expect.objectContaining({
countryCode: 'US',
countryName: 'United States',
code: 'US-IN',
regionCode: 'IN',
name: 'Indiana'
}))
expect(iso3166.subdivision('UN-1')).toBe(null)
expect(iso3166.subdivision('UN', '1')).toBe(null)
expect(iso3166.subdivision('UNN-1')).toBe(null)
})
describe('general', () => {
const { codes, data } = iso3166
test.each(Object.entries(codes))('%s', (code3, code2) => {
expect(code2).toHaveLength(2)
expect(code3).toHaveLength(3)
expect(data[code2]).toBeDefined()
})
})