-
Notifications
You must be signed in to change notification settings - Fork 0
set up Jest at Vite project
leetrue edited this page Nov 28, 2023
·
1 revision
yarn add -D jest @types/jest ts-node ts-node ts-jest @testing-library/react identity-obj-proxy jest-environment-jsdom @testing-library/jest-dom jest-svg-transformer
"scripts":{
"test": "jest"
}
- create
jest.config.ts
at root
export default {
testEnvironment: "jsdom",
transform: {
"^.+\\.tsx?$": "ts-jest",
},
moduleNameMapper: {
"^.+\\.svg$": "jest-svg-transformer",
"\\.(css|less|sass|scss)$": "identity-obj-proxy",
},
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
};
- create
jest.setup.ts
at root
import '@testing-library/jest-dom';
- if it doesn't work, try
import "@testing-library/jest-dom/extend-expect";
- if lint error occurs, try this.
// .eslintrc.cjs
module.exports = {
env: {
...,
module: "node",
}
}
{
"compilerOptions": {
"esModuleInterop": true
}
}