Documentación oficial sobre Jest
- Instalaciones de desarrollo (super test es útil para probar Express)
npm install -D jest @types/jest ts-jest supertest
- Crear archivo de configuración de Jest
npx jest --init
- En el archivo jest.config.js configurar
preset: 'ts-jest',
testEnvironment: "jest-environment-node",
// Opcional - The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: ['dotenv/config'],
- Crear scripts en el package.json
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
Dejo mi configuración para usar path aliases
{ "compilerOptions": { "target": "es2016", "module": "commonjs", "rootDir": ".", "baseUrl": ".", "paths": { "@src/*": ["src/*"] }, "outDir": "./dist", "strict": true, "esModuleInterop": true, "skipLibCheck": true }, "include": ["src/**/*", "test/**/*"], "exclude": ["node_modules", "dist"] }Esto les permitira realizar importaciones como la siguiente