next-international
next-international copied to clipboard
Unit testing with createI18nServer in server-side components throws server-only error
Describe the bug
I encountered a server-only
error when using createI18nServer
in server-side components for unit testing.
To Reproduce Steps to reproduce the behavior:
- Use
createI18nServer
in a server-side component. - Run the unit tests.
Expected behavior
Screenshots
// demo.test.tsx
import { describe, it, vi } from 'vitest'
import { render, screen, waitFor } from './customRender'
import { createI18nServer } from 'next-international/server'
describe('Example test', () => {
vi.mock("@server-only", () => ({}));
it('just an example', async () => {
const { getI18n } = createI18nServer({
en: () => import('../locales/messages/enUS'),
})
async function App() {
const t = await getI18n()
return <p>{t("login.welcome")}</p>
}
render(
<App/>
)
await waitFor(() => {
expect(screen.getByText('Welcome to the platform')).toBeInTheDocument()
})
})
})
About (please complete the following information):
- next-international version [ 1.2.4]
- Next.js version [14.2.1]
- Vitest version [1.6.0]