2021-07-24 20:00:06 +08:00
|
|
|
import { t, use, i18n, restoreHandler } from '../index'
|
2020-11-09 14:53:43 +08:00
|
|
|
import zhCn from '../lang/zh-cn'
|
2020-08-03 21:32:59 +08:00
|
|
|
import en from '../lang/en'
|
2020-08-03 19:16:13 +08:00
|
|
|
|
|
|
|
describe('Locale', () => {
|
|
|
|
test('t', () => {
|
|
|
|
expect(t('el.popconfirm.confirmButtonText')).toBe('Yes')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('return key name if not defined', () => {
|
2020-09-16 14:49:21 +08:00
|
|
|
expect(t('el.popconfirm.someThing')).toBeUndefined()
|
2020-08-03 19:16:13 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('use', () => {
|
|
|
|
use(zhCn)
|
|
|
|
expect(t('el.popconfirm.confirmButtonText')).toBe('确定')
|
2020-08-03 21:32:59 +08:00
|
|
|
use(en)
|
2021-07-23 23:02:16 +08:00
|
|
|
expect(t('el.popconfirm.confirmButtonText')).toBe('Yes')
|
2020-08-03 19:16:13 +08:00
|
|
|
})
|
2021-07-24 20:00:06 +08:00
|
|
|
|
|
|
|
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()
|
|
|
|
})
|
2020-08-03 19:16:13 +08:00
|
|
|
})
|