Implementing tests with Jest
Jest is a popular testing framework for TypeScript and React projects. It provides everything you need (functions, assertions, and so on) to test your code, including regular TypeScript classes and React components for UI tests. This is typically the preferred test framework for SPFx.
Preparing the test environment
The first step is to add the necessary dependencies so that we can test our code. In the package.json file, add the following packages:
"devDependencies": {
...
"jest": "^29.5.0",
"ts-jest": "^29.1.0",
"@types/jest": "~29.5.3"
"jest-environment-jsdom": "^29.5.0",
"identity-obj-proxy": "^3.0.0",
"@testing-library/jest-dom": "~5.16.5",
...