Skip to content

Instantly share code, notes, and snippets.

@nicolas-lizarazo
Forked from Klerith/pasos-node-ts-jest.md
Last active January 5, 2026 21:09
Show Gist options
  • Select an option

  • Save nicolas-lizarazo/65a0b71ed508148d7f793ca2ae7578ea to your computer and use it in GitHub Desktop.

Select an option

Save nicolas-lizarazo/65a0b71ed508148d7f793ca2ae7578ea to your computer and use it in GitHub Desktop.
Note + TypeScript + Jest = Testing

Pasos para configurar Jest con TypeScript, en Node

Documentación oficial sobre Jest

  1. Instalaciones de desarrollo (super test es útil para probar Express)
npm install -D jest @types/jest ts-jest supertest
  1. Crear archivo de configuración de Jest
npx create-jest
  1. 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'],
  1. Crear scripts en el package.json
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
@nicolas-lizarazo
Copy link
Author

Pongo mi configuracion por si alguno esta usando "type": "module", Dentro del package.json

{
  "name": "02-bases",
  "version": "0.0.1",
  "description": "Esta es mi primera aplicacion real de node",
  "license": "ISC",
  "author": "\"Nico\"",
  "type": "module",
  "main": "app.js",
  "scripts": {
    "dev": "tsx watch src/app.ts",
    "build": "rimraf ./dist && tsc",
    "start": "npm run build && node dist/app.js",
    "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
    "test:watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch",
    "test:coverage": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage"
  },
  "devDependencies": {
    "@types/jest": "^30.0.0",
    "@types/mocha": "^10.0.10",
    "@types/node": "^25.0.3",
    "jest": "^30.2.0",
    "nodemon": "^3.1.11",
    "rimraf": "^6.1.2",
    "supertest": "^7.1.4",
    "ts-jest": "^29.4.6",
    "ts-node": "^10.9.2",
    "tsx": "^4.21.0",
    "typescript": "^5.9.3"
  },
  "dependencies": {
    "axios": "^1.13.2",
    "chalk": "^5.6.2",
    "get-age": "^1.0.1",
    "inquirer": "^13.1.0",
    "uuid": "^13.0.0",
    "winston": "^3.19.0"
  }
}

@nicolas-lizarazo
Copy link
Author

Agregar esto antes de compiler options en ts.config para evitar ver error Jest fuera de rootdic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment