2018-10-24 17:43:19 -04:00
|
|
|
import Translator from '../src/Translator';
|
2018-10-26 17:50:34 -04:00
|
|
|
import { configure, t, tn } from '../src/TranslatorSingleton';
|
2018-10-24 17:43:19 -04:00
|
|
|
import languagePackZh from './languagePacks/zh.json';
|
|
|
|
|
|
|
|
describe('TranslatorSingleton', () => {
|
|
|
|
describe('before configure()', () => {
|
|
|
|
describe('t()', () => {
|
|
|
|
it('throws error', () => {
|
|
|
|
expect(() => t('second')).toThrow();
|
|
|
|
});
|
|
|
|
});
|
2018-10-26 17:50:34 -04:00
|
|
|
describe('tn()', () => {
|
|
|
|
it('throws error', () => {
|
|
|
|
expect(() => tn('ox', 'oxen', 2)).toThrow();
|
|
|
|
});
|
|
|
|
});
|
2018-10-24 17:43:19 -04:00
|
|
|
});
|
|
|
|
describe('after configure()', () => {
|
|
|
|
describe('configure()', () => {
|
|
|
|
it('creates and returns a translator', () => {
|
|
|
|
expect(configure()).toBeInstanceOf(Translator);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('t()', () => {
|
|
|
|
it('after configure() returns translated text', () => {
|
|
|
|
configure({
|
|
|
|
languagePack: languagePackZh,
|
|
|
|
});
|
|
|
|
expect(t('second')).toEqual('秒');
|
|
|
|
});
|
|
|
|
});
|
2018-10-26 17:50:34 -04:00
|
|
|
describe('tn()', () => {
|
|
|
|
it('after configure() returns translated text with singular/plural', () => {
|
|
|
|
configure({
|
|
|
|
languagePack: languagePackZh,
|
|
|
|
});
|
|
|
|
expect(tn('ox', 'oxen', 2)).toEqual('oxen');
|
|
|
|
});
|
|
|
|
});
|
2018-10-24 17:43:19 -04:00
|
|
|
});
|
|
|
|
});
|