-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.spec.ts
44 lines (37 loc) · 1.15 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
import { pluginDidLoad } from './index'
jest.mock('fs-extra', () => ({
readJsonSync: jest.fn(() => ({ 丹陽: 'Dan Yang' })),
}))
describe('legacy i18n polyfill', () => {
beforeEach(() => {
delete window.i18n
})
it('should creeate a polyfill on window', async () => {
window.language = 'en-US'
await pluginDidLoad()
expect(window.i18n).toMatchInlineSnapshot(`
Object {
"resources": Object {
"__": [Function],
"__n": [Function],
"fixedT": [Function],
"setLocale": [Function],
},
"translator": Object {
"__": [Function],
"__n": [Function],
"fixedT": [Function],
"setLocale": [Function],
},
}
`)
expect(window.i18n?.resources?.__?.('丹陽')).toMatchInlineSnapshot(`"Dan Yang"`)
expect(window.i18n?.resources?.__?.('雪風')).toMatchInlineSnapshot(`"雪風"`)
expect(window.i18n?.resources).toBe(window.i18n?.translator)
})
it('should not initialize with main window', async () => {
window.isMain = true
await pluginDidLoad()
expect(window.i18n).toMatchInlineSnapshot(`undefined`)
})
})