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.
Its impossible to test if you have environment variables, jest does not supports import.meta :sad:
I follow exactly all the steps but with npm test I get: echo 'Error: no test specified'
Found the problem, I needed to add "test": test inside script: {...} in package.json and install also jest-environment-jsdom with npm install jest-environment-jsdom