diff --git a/examples/test-vitest/.gitignore b/examples/test-vitest/.gitignore new file mode 100644 index 00000000..472010b4 --- /dev/null +++ b/examples/test-vitest/.gitignore @@ -0,0 +1,35 @@ +# compiled output +/dist +/node_modules + +# Logs +logs +*.log +npm-debug.log* +pnpm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# OS +.DS_Store + +# Tests +/coverage +/.nyc_output + +# IDEs and editors +/.idea +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json diff --git a/examples/test-vitest/@types/i18next.d.ts b/examples/test-vitest/@types/i18next.d.ts new file mode 100644 index 00000000..4bb27ff4 --- /dev/null +++ b/examples/test-vitest/@types/i18next.d.ts @@ -0,0 +1,18 @@ +/** + * If you want to enable locale keys typechecking and enhance IDE experience. + * + * Requires `resolveJsonModule:true` in your tsconfig.json. + * + * @link https://www.i18next.com/overview/typescript + */ +import 'i18next' + +// resources.ts file is generated with `npm run toc` +import resources from './resources.ts' + +declare module 'i18next' { + interface CustomTypeOptions { + defaultNS: 'common' + resources: typeof resources + } +} diff --git a/examples/test-vitest/@types/resources.ts b/examples/test-vitest/@types/resources.ts new file mode 100644 index 00000000..a955d5c6 --- /dev/null +++ b/examples/test-vitest/@types/resources.ts @@ -0,0 +1,11 @@ +import common from '../public/locales/en/common.json'; +import footer from '../public/locales/en/footer.json'; +import secondpage from '../public/locales/en/second-page.json'; + +const resources = { + common, + footer, + 'second-page': secondpage +} as const; + +export default resources; diff --git a/examples/test-vitest/components/Footer.test.tsx b/examples/test-vitest/components/Footer.test.tsx new file mode 100644 index 00000000..e8b8ace6 --- /dev/null +++ b/examples/test-vitest/components/Footer.test.tsx @@ -0,0 +1,26 @@ +import { render, screen } from "@testing-library/react"; +import { describe, expect, it, vi } from "vitest"; +import { Footer } from "./Footer"; + +vi.mock("next-i18next", () => ({ + Trans: ({ children }: { children: React.ReactNode }) => <>{children}, + useTranslation: () => ({ + t: (key: string) => key, + }), +})); + +vi.mock("next-i18next/package.json", () => ({ + default: { version: "1.0.0" }, +})); + +describe("Footer", () => { + it("renders correctly", () => { + render(