/
plugin.test.ts
70 lines (56 loc) · 1.75 KB
/
plugin.test.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* eslint-disable @typescript-eslint/no-empty-function */
// directive
vitest.mock('../src/directive')
// utils
import * as shared from '@intlify/shared'
vi.mock('@intlify/shared', async () => {
const actual = await vi.importActual<object>('@intlify/shared')
return {
...actual,
warn: vi.fn()
}
})
import { createApp } from 'vue'
import { I18n, I18nInternal } from '../src/i18n'
import { apply } from '../src/plugin/next'
import { getWarnMessage, I18nWarnCodes } from '../src/warnings'
describe('useI18nComponentName option', () => {
test('default', () => {
const mockWarn = vi.spyOn(shared, 'warn')
mockWarn.mockImplementation(() => {})
const app = createApp({})
const i18n = {} as I18n & I18nInternal
apply(app, i18n)
expect(mockWarn).not.toHaveBeenCalled()
})
test('true', () => {
const mockWarn = vi.spyOn(shared, 'warn')
mockWarn.mockImplementation(() => {})
const app = createApp({})
const i18n = {} as I18n & I18nInternal
apply(app, i18n, { useI18nComponentName: true })
expect(mockWarn).toHaveBeenCalled()
expect(mockWarn.mock.calls[0][0]).toEqual(
getWarnMessage(I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE, {
name: 'i18n-t'
})
)
})
})
describe('globalInstall option', () => {
test('default', () => {
const app = createApp({})
const i18n = {} as I18n & I18nInternal
const spy = vi.spyOn(app, 'component')
apply(app, i18n)
expect(spy).toHaveBeenCalled()
})
test('false', () => {
const app = createApp({})
const i18n = {} as I18n & I18nInternal
const spy = vi.spyOn(app, 'component')
apply(app, i18n, { globalInstall: false })
expect(spy).not.toHaveBeenCalled()
})
})
/* eslint-enable @typescript-eslint/no-empty-function */