|
| 1 | +import assert from 'power-assert' |
| 2 | +import Vue from 'vue' |
| 3 | +import locales from './fixture/locales' |
| 4 | + |
| 5 | +describe('custom formatter', () => { |
| 6 | + before(done => { |
| 7 | + Object.keys(locales).forEach(lang => { |
| 8 | + Vue.locale(lang, locales[lang]) |
| 9 | + }) |
| 10 | + Vue.config.lang = 'en' |
| 11 | + Vue.nextTick(done) |
| 12 | + }) |
| 13 | + |
| 14 | + after(done => { |
| 15 | + Vue.config.i18nFormatter = null |
| 16 | + Vue.nextTick(done) |
| 17 | + }) |
| 18 | + |
| 19 | + describe('global', () => { |
| 20 | + it('allows for specifying a custom formatter', done => { |
| 21 | + Vue.config.i18nFormatter = (string, ...args) => { |
| 22 | + assert.equal('the world', string) |
| 23 | + assert.equal(1, args[0]) |
| 24 | + assert.equal('two', args[1]) |
| 25 | + assert.deepEqual({ name: 'joe' }, args[2]) |
| 26 | + done() |
| 27 | + } |
| 28 | + |
| 29 | + Vue.t('message.hello', 1, 'two', { name: 'joe' }) |
| 30 | + }) |
| 31 | + }) |
| 32 | + |
| 33 | + describe('instance', () => { |
| 34 | + it('allows for specifying a custom formatter', done => { |
| 35 | + const vm = new Vue() |
| 36 | + Vue.config.i18nFormatter = (string, ...args) => { |
| 37 | + assert.equal('the world', string) |
| 38 | + assert.equal(1, args[0]) |
| 39 | + assert.equal(2, args[1]) |
| 40 | + assert.equal(3, args[2]) |
| 41 | + done() |
| 42 | + } |
| 43 | + |
| 44 | + vm.$t('message.hello', [1, 2, 3]) |
| 45 | + }) |
| 46 | + }) |
| 47 | +}) |
0 commit comments