I am trying to figure out how to use the JS Test Driver assertException correctly. From google documentation should be: assertException ([msg], callback, error). However, no matter what I do, I always get [ERROR] for this test (instead of [PASS], because 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 result 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):
Over the course of my life, I canβt understand how to make the code in the assertException callback, actually throw an exception without throwing it ERROR in the test - isnβt that what should happen?
Any help would be appreciated.
source share