blessing-skin-server/resources/assets/tests/js/i18n.test.ts

59 lines
1.2 KiB
TypeScript
Raw Normal View History

2019-03-15 11:42:41 +08:00
import { trans } from '@/js/i18n'
import Vue from 'vue'
2018-09-07 10:44:57 +08:00
test('mount to global', () => {
2019-03-15 11:42:41 +08:00
expect(window.trans).toBe(trans)
})
2019-03-17 10:21:18 +08:00
2018-09-07 10:44:57 +08:00
test('translate text', () => {
2019-03-15 11:42:41 +08:00
window.blessing.i18n = { a: { b: { c: 'text', d: 'Hi, :name!' } } }
expect(trans('a.b.c')).toBe('text')
expect(trans('a.b.d')).toBe('Hi, :name!')
expect(trans('a.b.d', { name: 'me' })).toBe('Hi, me!')
expect(trans('d.e')).toBe('d.e')
})
2019-03-17 10:21:18 +08:00
2018-09-07 10:44:57 +08:00
test('Vue directive', () => {
2019-03-15 11:42:41 +08:00
const byString = Vue.extend({
render(h) {
return h('div', {
directives: [
{
name: 't',
value: 'abc',
},
],
})
},
})
expect((new Vue(byString)).$mount().$el.textContent).toBe('abc')
2018-09-07 10:44:57 +08:00
2019-03-15 11:42:41 +08:00
const byObject = Vue.extend({
render(h) {
return h('div', {
directives: [
{
name: 't',
value: { path: 'abc', args: '123' },
},
],
})
},
})
expect((new Vue(byObject)).$mount().$el.textContent).toBe('abc')
2018-09-07 10:44:57 +08:00
2019-03-15 11:42:41 +08:00
const invalid = Vue.extend({
render(h) {
return h('div', {
directives: [
{
name: 't',
value: 123,
},
],
})
},
})
expect((new Vue(invalid)).$mount().$el.textContent).toBe('')
})