svelte-i18n/test/runtime/configs.test.ts

47 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-11-05 14:01:23 +01:00
import { get } from 'svelte/store';
2019-11-26 03:09:05 +01:00
import {
2019-11-27 04:58:53 +01:00
init,
getOptions,
defaultOptions,
defaultFormats,
2020-11-05 14:01:23 +01:00
} from '../../src/runtime/configs';
import { $locale } from '../../src/runtime/stores/locale';
beforeEach(() => {
2020-11-05 14:01:23 +01:00
init(defaultOptions);
});
2019-11-26 03:09:05 +01:00
2019-11-27 04:58:53 +01:00
test('inits the fallback locale', () => {
2020-11-05 14:01:23 +01:00
expect(getOptions().fallbackLocale).toBeNull();
2019-11-27 04:58:53 +01:00
init({
fallbackLocale: 'en',
2020-11-05 14:01:23 +01:00
});
expect(getOptions().fallbackLocale).toBe('en');
});
2019-11-27 04:58:53 +01:00
test('inits the initial locale by string', () => {
init({
fallbackLocale: 'pt',
initialLocale: 'en',
2020-11-05 14:01:23 +01:00
});
expect(getOptions().initialLocale).toBe('en');
expect(get($locale)).toBe('en');
});
test('adds custom formats for time, date and number values', () => {
2020-11-05 14:01:23 +01:00
const customFormats = require('../fixtures/formats.json');
2019-11-27 04:58:53 +01:00
init({
2019-11-26 03:09:05 +01:00
fallbackLocale: 'en',
formats: customFormats,
2020-11-05 14:01:23 +01:00
});
expect(getOptions().formats).toMatchObject(defaultFormats);
expect(getOptions().formats).toMatchObject(customFormats);
});
test('sets the minimum delay to set the loading store value', () => {
2020-11-05 14:01:23 +01:00
init({ fallbackLocale: 'en', loadingDelay: 300 });
expect(getOptions().loadingDelay).toBe(300);
});