Correct syntax for JS Test Driver "assertException"?

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.

+4
source share
1 answer
 assertException(function(){ this.component = new myNamespace.component(this.testComponentSettings); }, "Error"); 

the error argument must be Error.name from the error that was reset (for example, "ReferenceError", "TypeError", etc.).

+4
source

Source: https://habr.com/ru/post/1380067/


All Articles