Course lesson

Adding Jest with TypeScript Support to a Vite Application

The app is built on top of vite instead of the more popular create react app. The benefit of vite is that it installs and builds extremely quickly. One of the downsides of vite is that it doesn't come with any out-of-the-box testing support. It also has its...

Duration
3 min
Access
Free
Transcript
Available

The app is built on top of vite instead of the more popular create react app. The benefit of vite is that it installs and builds extremely quickly. One of the downsides of vite is that it doesn't come with any out-of-the-box testing support. It also has its own esbuild-based compiler, which is not currently compatible with jest, so we have to configure JSX & TypeScript support for jest even though vite handles that already for our app.

This lesson requires installing a handful of modules:

npm install -D jest
npm install -D @testing-library/react @testing-library/jest-dom @testing-library/user-event
npm install -D @babel/preset-react @babel/preset-typescript @babel/preset-env
npm install -D identity-obj-proxy

Each of them serves an important purpose:

We also have to add numerous config files such as babel.config.js and jest-setup.ts which are required to enable all of this functionality.

We put our jest config in our package.json file which works well, but you can also put it in a file named jest.config.ts or jest.config.js. See the Jest Configuration Documentation for more details about configuring jest.