Files
2026-03-26 11:56:48 -05:00

27 lines
757 B
TypeScript

import { describe, it, expect } from 'vitest';
import { createI18n } from '$lib/i18n';
describe('i18n', () => {
const i18n = createI18n({
'common.save': 'Save',
'common.cancel': 'Cancel',
'pets.title': 'Our Pets',
'pets.count': '{count} pets available',
'greeting': 'Hello, {name}!'
});
it('returns translated string by key', () => {
expect(i18n.t('common.save')).toBe('Save');
expect(i18n.t('pets.title')).toBe('Our Pets');
});
it('returns key when translation is missing', () => {
expect(i18n.t('missing.key')).toBe('missing.key');
});
it('interpolates variables', () => {
expect(i18n.t('greeting', { name: 'Justin' })).toBe('Hello, Justin!');
expect(i18n.t('pets.count', { count: '5' })).toBe('5 pets available');
});
});