Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct syntax for JS Test Driver "assertException"?

I'm trying to figure out how to correctly use JS Test Driver's assertException method. From google's documentation it should be: assertException([msg], callback, error). However, no matter what I do, I always get an [ERROR] for this test (instead of a [PASS] since there was an exception):

ComponentTest.prototype.testEnforceUniqueComponentIds = function() {
    assertException(function(){
        this.component = new myNamespace.component(this.testComponentSettings);
    });
}

And in my src JS:

myNamespace.component = function(params){
if (typeof params.selector == 'undefined'){
    throw new Error('no selector provided');
}
this.settings = jQuery.extend({}, {
    id              : 'defaultComponentId',
    type            : 'defaultComponentType',
    selector    : 'body',
    isUnique    : false
}, params);

if(typeof(myNamespace.componentRegistry[params.id]) === "undefined"){
    myNamespace.registerComponent(this);
} else {
    throw new Error('non-unique component id provided');
}
}

Here is the output from js-test-driver:

C:\xampp2\htdocs\myNamespace\v2>java -jar JsTestDriver.jar --tests all --verbose
[PASSED] ComponentTest.testInit
  [LOG] setUp
  [LOG] tearDown
[PASSED] ComponentTest.testDestroy
  [LOG] setUp
  [LOG] tearDown
[ERROR] ComponentTest.testEnforceUniqueComponentIds
  [LOG] setUp
Total 3 tests (Passed: 2; Fails: 0; Errors: 1) (1.00 ms)
  Firefox 7.0.1: Run 3 tests (Passed: 2; Fails: 0; Errors 1) (1.00 ms)
    ComponentTest.testEnforceUniqueComponentIds error (1.00 ms):

For the life of me, I can't figure out how to have the code within the assertException callback actually throw an exception without it causing an ERROR in the test - isn't this what is supposed to happen?

Any help would be appreciated.

like image 989
hous Avatar asked Oct 09 '22 13:10

hous


1 Answers

assertException(function(){
    this.component = new myNamespace.component(this.testComponentSettings);
}, "Error");

error argument should be Error.name of thrown error(such as "ReferenceError", "TypeError", etc.).

like image 157
zaquest Avatar answered Nov 07 '22 15:11

zaquest