Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

397
Visualizações
Debugging Angular Tests with Jest in Visual Studio Code

Our project is currently using jest for Angular tests. We use jest-preset-angular and it is configured to run in debug mode within Visual Studio Code. The debugging works except that it first converts the spec.ts files to JavaScript. This means that the breakpoint is usually not where I want it to be as the file has been transformed from TypeScript to JavaScript.

How can I configure my project so that I can debug my tests as Typescript within Visual Studio Code?

I have tried running Karma along side Jest as the Karma experience for debugging in the browser is much easier. However, there are so many Jest dependencies within the tests that this is also a challenge.

launch.json
    {
      "name": "Tests",
      "type": "node",
      "request": "launch",
      "program": "${workspaceRoot}/node_modules/jest-cli/bin/jest.js",
      "stopOnEntry": false,
      "args": ["-i", "-o"],
      "cwd": "${workspaceRoot}",
      "preLaunchTask": null,
      "runtimeExecutable": null,
      "env": {
        "NODE_ENV": "test"
      },
      "console": "integratedTerminal",
      "outFiles": ["${workspaceRoot}/dist/**/*"],
      "sourceMaps": true
    }

package.json

  "jest": {
    "preset": "jest-preset-angular",
    "setupFilesAfterEnv": [
      "<rootDir>/setupJest.ts"
    ],
    "moduleDirectories": [
      "node_modules",
      "./"
    ],
    "testResultsProcessor": "jest-teamcity-reporter",
    "testMatch": [
      "**/app/**/*.spec.ts"
    ]

tsconfig.spec.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "outDir": "../out-tsc/spec",
    "module": "commonjs",
    "types": ["jest", "node"]
  },
  "files": ["src/test.ts", "src/polyfills.ts"],
  "include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I finally came across a suggestion in an article by Micha Pierzchala that was linked on https://jestjs.io/docs/testing-frameworks#angular. The article recommends IDE integrations, with the one for VS Code being vscode-jest. This is exactly what I was looking for and provides a fantastic debugging experience for your TypeScript code.

I didn't have to change anything about my jest configuration. I simply added this extension to my VS Code workspace.

enter image description here

Edit: I found vscode-jest to be quite buggy, thus I switched to vscode-jest-runner. With this extension, you initiate the test from a right-click-context menu. It has the same result in making the debugging experience much more pleasant for your TypeScript code.

enter image description here

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda