Search code examples
dojotdddoh

How to check if function throw an error in DOH?


I'm trying to check if a function throws error, and made this:

 define([
     'doh/runner',
     'app/Obj'
 ], function(
     doh,    
     Obj 
 ){
     doh.register('Test Obj exception', [
         function () {
             try {          
                 new Obj(); // should throw error
             } catch(e) {
                 doh.t(e, 'should give an error if no parameters given');               
             }
         }
 ]);

Obj.js file:

...
constructor: function (args){
  if (!args) { throw 'Error' }
  ...
}
...

But maybe where is some right method for this thing in Doh ? Can someone explain? Thanks


Solution

  • You want doh.assertError()

    Example:

    doh.assertError(TypeError, this.field, "setValue",
        [{
            CreatedOn: "March 10th, 2014"
        }],
        "setValue() on an invalid format should throw a TypeError");