/ jasmine

Debugging Jasmine Test Cases with Visual Studio Code

Visual Studio Code is an awesome editor for NodeJS development and debugging. It provides awesome support for IntelliSense and debugging and made it my favorite as compared to Atom or Sublime Editor. Check out the more details of Visual Studio Code here. Debugging Jasmine test cases via conventional ways is a pain in the ass, but not with VS Code.

Debugging Jasmine Test Cases

Debugging Jasmine Test Cases could be a pain in the ass if you want to debug it in the Chrome Dev Tools, especially because the runtime is not your test case.

  1. To debug in Visual Studio code, you will need to create a debugger configuration file launch.json. You will see an Activity bar on the left, navigate to it and then configure gear icon at the top of the Debug view to create a default file launch.json.

  2. You will get a default NodeJS launch configuration. We will update it to add our Jasmine test configurations. We will update the launch configuration as follows.

"configurations": [ 
    { 
        "type": "node", 
        "request": "launch", 
        "name": "Jasmine Individual Test", 
        "program": "${workspaceRoot}\\node_modules\\jasmine\\bin\\jasmine.js", 
        "args": [ 
            "spec\\todoSpec.js" 
        ], 
        "env": { 
            "NODE_PATH": "." 
        } 
   }
]

In the above launch snippet, we are testing a spec called “todoSpec.js” and launching it using node and the Jasmine run-time specified as the program name. We can add additional environment variables as shown above.

You can also skip the program arguments and run it to debug and execute all the jasmine test cases you have if you already defined the jasmine configuration.

you can check out more launch and debug configurations of VS Code here.

Love Hasija

Love Hasija

Full Stack Research Engineer, Software Architect | Helped build next generation software systems | Distributed Systems Fanatic | Open Source Hacker.

Read More