Skip to content

Instantly share code, notes, and snippets.

@runtimevic
Forked from Klerith/pasos-node-ts-jest.md
Created February 25, 2024 13:20
Show Gist options
  • Save runtimevic/853f9024f8ebb4c2cefb6af03e0e3cfb to your computer and use it in GitHub Desktop.
Save runtimevic/853f9024f8ebb4c2cefb6af03e0e3cfb to your computer and use it in GitHub Desktop.

Revisions

  1. @Klerith Klerith created this gist Aug 19, 2023.
    31 changes: 31 additions & 0 deletions pasos-node-ts-jest.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    # Pasos para configurar Jest con TypeScript, en Node

    Documentación [oficial sobre Jest](https://jestjs.io/docs/getting-started)


    1. Instalaciones de desarrollo (super test es útil para probar Express)
    ```
    npm install -D jest @types/jest ts-jest supertest
    ```

    2. Crear archivo de configuración de Jest
    ```
    npx jest --init
    ```

    3. 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'],
    ```

    4. Crear scripts en el **package.json**
    ```
    "test": "jest",
    "test:watch": "jest --watch",
    "test:coverage": "jest --coverage",
    ```