Abusing Javascript: Is it possible to have helper methods for nodeunit?

297 views Asked by At

Does nodeunit have helper methods that I can place inside exports.MYTEST?

I am currently doing something like that:

exports.test = {
  setup: function(test) { 
    this.foo = "bar";
  }, 
  helper: function(test) { 
    that.foo = 'baz';
  },
  myTest: function(test) { 
    that.helper(test); 
  }
};

var that = exports.test;

I know I am abusing javascript but currently this works pretty well.

Before everyone gets all worked up about how unit testing shouldn't involve something like that, I just want to do this because I find it pretty helpful to have helper methods that exist inside this object.

1

There are 1 answers

0
Raynos On
exports.test = {
  setup: function(test) { 
    this.foo = "bar";
  }, 
  myTest: function(test) { 
    helper.call(this, test); 
  }
};

function helper(test) {
    this.foo = 'baz';
}

I would say functions are better for this kind of behaviour