Replies: 4 comments 6 replies
-
Hey @tommaton and thanks for the question! The unit testing story for using Have you written tests for Server Components apart from Off the top of my head there are two potential solutions here that would work immediately:
Does this help? Personally, when it comes to Server Components I'm using e2e testing frameworks. |
Beta Was this translation helpful? Give feedback.
-
Hi,
|
Beta Was this translation helpful? Give feedback.
-
@aXenDeveloper Thanks for providing your solution! I replaced Jest with Vitest using your example, it fixed my syntax errors. I also made an update to your code so I don't need to have the This is what I added: // vitest.setup.ts
import { createTranslator, useTranslations } from "next-intl";
vi.mock("next-intl", async () => {
const actual = (await vi.importActual("next-intl")) as any;
return {
...actual,
useTranslations: vi.fn(),
};
});
beforeAll(async () => {
const translate = createTranslator({
locale: "en",
messages: (await import("./src/messages/en.json")).default,
});
(useTranslations as Mock).mockImplementation(() => translate);
}); |
Beta Was this translation helpful? Give feedback.
-
i modified @lucas-av7 's a bit so we can access namespace like useTranslations("common") // vitest.setup.ts
vi.mock('next-intl', async (importActual) => ({
...((await importActual()) as any),
useTranslations: vi
.fn()
.mockImplementation((namespace: any) =>
createTranslator({locale: 'en', messages: en, namespace})
),
})); |
Beta Was this translation helpful? Give feedback.
-
Hi all,
I've been trying out the latest 2.11.0-beta.15 version with the app directory of Nextjs 13.1.6.
We've created a RSC with
next-intl
and have it rendering on the page as it should. When we come to write some unit tests for the component we're getting an errorThis is our component:
test:
our next.config
packages:
Any help would be greatly appreciated as I'm beginning to pull my hair now
Beta Was this translation helpful? Give feedback.
All reactions