mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-15 09:50:58 +08:00
55348b30b6
* style: use prettier * style: just prettier format, no code changes * style: eslint fix object-shorthand, prefer-const * style: fix no-void * style: no-console
35 lines
877 B
TypeScript
35 lines
877 B
TypeScript
import { t, use, i18n, restoreHandler } from '../index'
|
|
import zhCn from '../lang/zh-cn'
|
|
import en from '../lang/en'
|
|
|
|
describe('Locale', () => {
|
|
test('t', () => {
|
|
expect(t('el.popconfirm.confirmButtonText')).toBe('Yes')
|
|
})
|
|
|
|
test('return key name if not defined', () => {
|
|
expect(t('el.popconfirm.someThing')).toBeUndefined()
|
|
})
|
|
|
|
test('use', () => {
|
|
use(zhCn)
|
|
expect(t('el.popconfirm.confirmButtonText')).toBe('确定')
|
|
use(en)
|
|
expect(t('el.popconfirm.confirmButtonText')).toBe('Yes')
|
|
})
|
|
|
|
test('external i18n function', () => {
|
|
const emptyKey = 'el.popconfirm.confirmButtonText'
|
|
const translator = jest.fn().mockImplementation((k) => {
|
|
if (k === emptyKey) return ''
|
|
return k
|
|
})
|
|
|
|
i18n(translator)
|
|
const key = 'test'
|
|
expect(t(key)).toBe(key)
|
|
expect(t(emptyKey)).toBe('Yes')
|
|
restoreHandler()
|
|
})
|
|
})
|