-
Notifications
You must be signed in to change notification settings - Fork 13
/
test.js
56 lines (44 loc) · 1.77 KB
/
test.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
const assert = require('assert')
// Node api
const localizedCountries = require('./')
// .languages()
assert.strictEqual(Array.isArray(localizedCountries.languages()), true, 'Returns an array')
localizedCountries.languages().forEach(function (lang) {
assert.ok(typeof lang === 'string', '.languages() returns an array of strings')
})
// .get
const german = localizedCountries('de')
assert.strictEqual(german.get('CH'), 'Schweiz')
const english = localizedCountries('en')
assert.strictEqual(english.get('CH'), 'Switzerland')
const japanese = localizedCountries('ja')
assert.strictEqual(japanese.get('CH'), 'スイス')
assert.throws(function () {
localizedCountries('foo')
}, /Language "foo" not found/)
// .object
const enCountries = localizedCountries('en')
assert.strictEqual(typeof enCountries.object(), 'object', '.object() returns an object')
assert.strictEqual(
enCountries.object()['CH'],
'Switzerland', '.object() returns a code to label mapping.'
)
// .array
assert.ok(Array.isArray(enCountries.array()), '.array() an array')
enCountries.array().forEach(function (country) {
assert.strictEqual(typeof country, 'object')
assert.strictEqual(typeof country.code, 'string')
assert.strictEqual(typeof country.label, 'string')
assert.strictEqual(enCountries.get(country.code), country.label)
})
// Browser api
const browserApi = require('./browser')
assert.throws(function () {
browserApi()
}, /You have to pass a countries object/)
const browserGerman = browserApi(require('./data/de'))
assert.strictEqual(browserGerman.get('CH'), 'Schweiz')
const browserEnglish = browserApi(require('./data/en'))
assert.strictEqual(browserEnglish.get('CH'), 'Switzerland')
const browserJapanese = browserApi(require('./data/ja'))
assert.strictEqual(browserJapanese.get('CH'), 'スイス')