Setting Up Tests For React + Vite + TypeScript Apps
Set up tests for React + Vite + TS: Install jest, ts-jest, configure jest.config.ts, update tsconfig.json & vite.config.ts. Handle absolute imports with vite-tsconfig-paths & baseUrl in tsconfig.json. Get test coverage report via Jest.
Recently, I have been learning to write some tests in React using Jest and RTL(React Testing Library), which has been a fun and eye-opening adventure so far. Setting up testing in a Nextjs app which I used to practise testing was not too complicated, and I managed to get things working. I recently wanted to start writing some tests for a project I am working on which is a React+Vitejs, and Typescript application. This proved challenging to set up, resulting in me looking through a few outdated articles here and there, pulling a hair or 2, and almost crying about why the gods of testing were ag...