import { describe, expect, it } from 'vitest'; import { nl, t, tList } from './index'; function leaves(node: unknown, path = ''): { path: string; value: unknown }[] { if (typeof node === 'string' || Array.isArray(node)) { return [{ path, value: node }]; } if (node && typeof node === 'object') { return Object.entries(node).flatMap(([key, child]) => leaves(child, path ? `${path}.${key}` : key), ); } return []; } describe('i18n texts', () => { const all = leaves(nl); it('has no empty texts', () => { const empty = all.filter(({ value }) => Array.isArray(value) ? value.some((v) => typeof v !== 'string' || v.trim() === '') : typeof value !== 'string' || value.trim() === '', ); expect(empty.map((e) => e.path)).toEqual([]); }); it('has only plain `{name}` placeholders', () => { const odd = all.filter( ({ value }) => typeof value === 'string' && /\{[^}\w]|\{\}|\{\w*$/.test(value), ); expect(odd.map((e) => e.path)).toEqual([]); }); it('falls back to the key for unknown keys', () => { expect(t('unknown.key' as never)).toBe('unknown.key'); expect(tList('unknown.list' as never)).toEqual([]); }); });