5

I have my unit tests written in jasmine and those are in typescript

// about.service.spec.ts
// say 4 to 5 test cases

// spec/support/jasmine.json
{
  "spec_dir": "src/tests/",
  "spec_files": ["**/*.spec.ts"],
  "helpers": ["jasmine-helpers/**/*.ts"],
  ...
}

// launch.json - vscode file
{
  "version": "0.2.0",
  "configurations": [{
      "type": "node",
      "request": "launch",
      "name": "Jasmine tests",
      "preLaunchTask": "debuggertests",
   }]
}

// tasks.json - vscode 
{
 "version": "2.0.0",
 "tasks": [{
    "label": "debuggertests",
    "type": "npm",
    "script": "test:unit",
    "problemMatcher": []
  }]
}

// package.json
// have to use jasmine-ts which is flavor over ts-node
"test:unit": "jasmine-ts JASMINE_CONFIG_PATH=spec/support/jasmine.json"

I have used this configuration to debug .spec.ts files in vscode but it did not fire debugger instead it run all tests and debugging started.

I have put a breakpoint in one of the test case of about.service.spec.ts but no breakpoint fired. Could anyone help me on setting up vscode debugging for jasmine tests?

2 Answers 2

10

In new jasmine-ts version, you have to include the jasmine.json to the args as this:

{
  "type": "node",
  "request": "launch",
  "name": "Jasmine Current File",
  "program": "${workspaceFolder}/node_modules/jasmine-ts/lib/index",
  "args": ["--config=jasmine.json", "${file}"],
  "console": "integratedTerminal",
  "internalConsoleOptions": "neverOpen"
}

To avoid this issue:

No specs found Finished in 0.003 seconds Incomplete: No specs found Randomized with seed 60766 (jasmine --random=true --seed=60766)

Sign up to request clarification or add additional context in comments.

Comments

6

Below configuration will debug current test file - please open the required test file in VS Code and start debugging with this configuration:

{
      "type": "node",
      "request": "launch",
      "name": "Jasmine Current File",
      "program": "${workspaceFolder}/node_modules/jasmine-ts/lib/index",
      "args": ["${file}"],
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen"
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.