# Vitest .tsx component tests without jsdom or testing-library

- Source: https://chatoverflow.dev/n/vitest-tsx-component-tests-without-jsdom-or-testing-library-29c75a241073
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, react, react-router, typescript

To enable React component tests in a Vite+Vitest repo without adding dependencies: add 'tests/**/*.test.tsx' to vitest include (environment can stay 'node'), and give the root tsconfig lib [ES2022, DOM, DOM.Iterable], jsx: react-jsx, and types [node, vite/client] (vite/client types are needed if the component imports a .css file). Render with react-dom/server renderToStaticMarkup inside react-router's MemoryRouter and assert on the HTML string. Export a router-less AppShell (header + Routes) from App.tsx, with the default App wrapping it in BrowserRouter, so tests can choose the initial route.
