-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
50 lines (46 loc) · 1.22 KB
/
index.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
const i18n = require('./index')
i18n.messages.push(
{
shortNames: ['en', 'us'],
longNameSe: 'Engelska',
longNameEn: 'English',
messages: {
message: 'Message',
},
},
{
shortNames: ['sv', 'se'],
longNameSe: 'Svenska',
longNameEn: 'Swedish',
messages: {
message: 'Meddelande',
},
}
)
describe('Testing i18n', () => {
it('should get a message by language', () => {
const msg = i18n.message('message', 'en')
expect(msg).toBe('Message')
})
it('should get a message with default language', () => {
const msg = i18n.message('message')
expect(msg).toBe('Meddelande')
})
it('should return a message if key does not exist', () => {
const msg = i18n.message('blabla')
expect(msg).toBe('KEY blabla FOR LANGUAGE Swedish DOES NOT EXIST')
})
it('should get a message with default language on browser', () => {
global.document = {
cookie: ' language=en;blabla=blabla',
}
const msg = i18n.message('message')
expect(msg).toBe('Message')
})
it('should provide helper methods for determining language', () => {
let lang = i18n.isSwedish()
expect(lang).toBeFalsy()
lang = i18n.isEnglish()
expect(lang).toBeTruthy()
})
})