Debugging unit test that makes a http://localhost call back into my WebStorm project?


I am running a unit test like so:

Creates some submissions and tries to save them
describe('canCreateAndSaveSubmissionModel',function() {
    it('tests that a model can be created and saved', function (done) {
        var numToCreate = 10;
        var helper = new HttpHelper();
        helper.getModel(function(status, model){
            var i = 0;
            var email = '';
            var legacySite = '';
            var talxSite = ' ';
            model["reporter"] = email;
            model["reportName"]="report-" + 0;
                assert.equal(200, status);
                assert.notEqual(data, undefined);


Here is the helper....

var http = require('http');
var events = require('events');
var request = require('superagent');
module.exports = HttpHelper;

HttpHelper.prototype.saveModel = function(model, onComplete){
    var modelString = JSON.stringify(model);
        .set('Accept', 'application/json')
        .end(function(err, res){
            console.log('res here');
            if (res.ok) {
                console.log('yay got ' + JSON.stringify(res.body));
            } else {
                console.log('Oh no! error ' + res.text);

Both the unit test and the POST code are running under my WebStorm project. I am running the unit test using a Mocha configuration. I put a break point in the code behind the POST endpoint. But, when I run the unit test, I can step through the test code, but the code on the other side of the HTTP call does not load, nor is the breakpoint respected.

Tell me please, how to do I make it so I can debug both the test and the code behind the HTTP call?

Thanks in advance.


Comment actions Permalink

Hey Bob,

Did you ever figure this out? I have the same issue. :-/

Comment actions Permalink

1. Set your break points in both the unit test and the server code
2. go to bin/www, right click and starte in Debug mode
3. go to your unit test file, right click and start in Debug.

Hope this helps.


Please sign in to leave a comment.