Repository navigation
Testing
📄 Mirrors
docs/testing.mdin the main repo — the repo version is canonical.
Status: planned / pre-release. This page documents the intended API of next-tongue. Nothing is published yet; names may change before v1.0. See ROADMAP.
import { createTestT } from 'next-tongue/testing';
const t = createTestT('de', 'home');
expect(t('inbox', { count: 2 })).toBe('2 Nachrichten');createTestT uses the same compiled modules as the app (run tongue build first, e.g. in a Vitest globalSetup; no Vite plugin needed).
import { render, screen } from '@testing-library/react';
import { TongueTestProvider } from 'next-tongue/testing';
render(<TongueTestProvider locale="de"><InboxBadge count={1} /></TongueTestProvider>);
expect(screen.getByText('1 Nachricht')).toBeInTheDocument();Pass keysOnly to render keys instead of text (home.inbox) for locale-independent snapshot tests.
Test the logic by calling the component function and rendering the result, or prefer e2e for RSC.
Test each locale's URL directly (/de/about) and test the proxy separately with Accept-Language headers:
test('redirects German browsers', async ({ browser }) => {
const ctx = await browser.newContext({ locale: 'de-DE' });
const page = await ctx.newPage();
await page.goto('/about');
await expect(page).toHaveURL(/\/de\/ueber-uns$/);
});Run tongue check before tests; it is faster than a build and catches most i18n regressions.
Guides
- Getting Started
- Configuration
- Routing and Proxy
- Server Components
- Client Components
- Server Actions
- ICU Messages
- Type Safety
- Cache Components and PPR
- Static Export
- Metadata SEO and hreflang
- Database and CMS Messages
- Dev Tools
- Translator Workflow
- Per-user Preferred Language
- CLI
- AI Translation
- Testing
- VS Code Extension
- Migration from next intl
- Migration from next international (deferred)
Reference