Search⌘ K
AI Features

Using TypeScript with Jest

Explore how to integrate TypeScript into your Jest testing setup for React applications. Learn to configure tsconfig.json, update Babel with the TypeScript preset, and install necessary type definitions. This lesson helps you run and maintain type-safe tests for more reliable code verification.

Installing and configuring TypeScript

The starter project for this lesson contains source code and tests written in TypeScript in the src folder. We’ll recognize the validEmailDomain function from previous lessons.

TypeScript can be installed by running the following in a terminal:

npm install --save-dev typescript

TypeScript is configured by a file called tsconfig.json. Create this file in the root of the project with the following content:

{
  "compilerOptions": {
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
   
...