-
+
{project.issuesCount} Issues
-
+
{project.repository}
{project.description}
-
+
Lang: {project.languages.join(", ")}
Learn more
diff --git a/tests/setup.ts b/tests/setup.ts
new file mode 100644
index 0000000..2ba240b
--- /dev/null
+++ b/tests/setup.ts
@@ -0,0 +1,7 @@
+import "@testing-library/jest-dom/vitest";
+import { afterEach } from "vitest";
+import { cleanup } from "@testing-library/react";
+
+afterEach(() => {
+ cleanup();
+});
diff --git a/tests/utils/index.tsx b/tests/utils/index.tsx
new file mode 100644
index 0000000..a3689a7
--- /dev/null
+++ b/tests/utils/index.tsx
@@ -0,0 +1,35 @@
+import {
+ createRootRoute,
+ createRoute,
+ createRouter,
+ RouterProvider,
+} from "@tanstack/react-router";
+import { render } from "@testing-library/react";
+import React from "react";
+
+/**
+ * Utility function for rendering a React component with routing context using `@tanstack/react-router`.
+ * Useful for testing components that rely on routing or are part of a routed application.
+ */
+export const renderWithRouter = (Comp: React.ComponentType) => {
+ const rootRoute = createRootRoute();
+
+ const indexRoute = createRoute({
+ getParentRoute: () => rootRoute,
+ path: "/",
+ component: () =>
,
+ });
+
+ const router = createRouter({
+ routeTree: rootRoute.addChildren([indexRoute]),
+ });
+
+ return render(
+
[0]["router"]
+ }
+ />,
+ );
+};
diff --git a/tsconfig.app.json b/tsconfig.app.json
index 0bd75c5..6a37266 100644
--- a/tsconfig.app.json
+++ b/tsconfig.app.json
@@ -5,6 +5,7 @@
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
+ "types": ["vitest/globals"],
/* Bundler mode */
"moduleResolution": "Bundler",
@@ -26,5 +27,5 @@
"~/*": ["./src/*"]
}
},
- "include": ["src"]
+ "include": ["src", "tests/setup.ts"]
}
diff --git a/tsconfig.node.json b/tsconfig.node.json
index a5d5964..ae78200 100644
--- a/tsconfig.node.json
+++ b/tsconfig.node.json
@@ -4,6 +4,7 @@
"lib": ["ES2023"],
"module": "ESNext",
"skipLibCheck": true,
+ "types": ["vitest/globals"],
/* Bundler mode */
"moduleResolution": "Bundler",
@@ -18,11 +19,11 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true,
- "baseUrl": ".",
+ "baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"~/*": ["./src/*"]
}
},
- "include": ["vite.config.ts"]
+ "include": ["vite.config.ts", "tests/setup.ts"]
}
diff --git a/vite.config.ts b/vite.config.ts
index a1a817c..ff70a9c 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -25,7 +25,10 @@ export default defineConfig({
host: true,
},
test: {
+ globals: true,
+ environment: "jsdom",
include: ["./src/**/*.{test,spec}.?(c|m)[jt]s?(x)"],
exclude: ["e2e-tests", "node_modules"],
+ setupFiles: "./tests/setup.ts",
},
});