https://github.com/daviddozie/jestreact
https://github.com/daviddozie/jestreact
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/daviddozie/jestreact
- Owner: daviddozie
- Created: 2024-02-20T16:35:07.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-20T16:37:21.000Z (about 1 year ago)
- Last Synced: 2025-02-20T11:50:15.919Z (3 months ago)
- Language: JavaScript
- Size: 90.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# React + Vite + Jest
# #INSTALLATION PROCESS:👇# Make sure you have the necessary packages installed. Run the following command in your project directory:
npm install --save-dev jest @types/jest ts-jest babel-jest.
# Create a jest.config.cjs file in your project root with the following content:
module.exports = {
preset: 'ts-jest/presets/js-with-babel',
testEnvironment: 'jest-environment-jsdom',
transform: {
'^.+\\.jsx?$': 'babel-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
setupFilesAfterEnv: ["@testing-library/react"],
};
# Update your package.json to include test scripts:
"scripts": {
"test": "jest",
"test:watch": "jest --watch",
}
# Create a .babelrc file in your project root with the following content:
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
}
# Install jest-environment-jsdom as a development dependency:
npm install --save-dev jest-environment-jsdom
# Update your Jest configuration to use the jest-environment-jsdom. You can do this by adding or updating the testEnvironment field in your jest.config.js:
module.exports = {
// other Jest configurations
testEnvironment: 'jest-environment-jsdom',
};
# Install the required Babel packages for handling JSX:
npm install --save-dev @babel/core @babel/preset-env @babel/preset-react babel-jest
# Make sure you have the required testing library dependencies installed. Run the following command in your project directory:
npm install --save-dev @testing-library/react @testing-library/jest-dom
# Make sure to import the React module:
import React from 'react';