javascript - Add append html to QUnit output results for specific tests -


i'm testing set of algorithms. each have same purpose have different results can viewed graphically in chart.

i have unit tests each algorithm. have link in appropriate qunit test output results opens graph algorithm being tested.

the problem can't find non-hack way of doing this. best idea far:

first, write test:

module("test algo 1");  test("test inputs 1", ...); test("test inputs 2", ...); 

then write separate code records link should added code:

addalgolink("test algo 1", "test inputs 1", function() {     // on click code link displays     // input/output data on graph }) 

then implementation of addalgolink() would:

  1. add callback qunit on completion of tests.
  2. on completion of tests, through dom of qunit results entries matching module name , test name, append link callback given addalgolink(). easier use qunit's hash id each test used in dom, can't find way of accessing test's id within test definition

problems:

  1. cannot handle multiple tests in module same name (although don't know if qunit supports anyway)
  2. it need complex code deal differing depths of tests (nested modules)
  3. it seems hacky.

perhaps qunit extended in more elegant way? e.g. within test code, method called specify on click callback gets inserted link such test , module name need not specified again. extend qunit results outputter display link. perhaps stored within qunit's test objects, although think or of methods etc needed private makes seem impossible (not have been idea).

is i'm trying bad idea in first place? or solution have messy?

the trick use qunit.config.current.testid within test record id.

first write test this:

qunit.test("test 1", function( assert ) {     addtestappendage("test 1", qunit.config.current.testid);     assert.ok(true); }); 

then use code added test in results , append button test results row runs closure when clicked.

var appendages = []; var addtestappendage = function(testname, testid){     appendages [testid] = testname; };  qunit.testdone(function(details){     if (typeof appendages[details.testid] !=== 'undefined')     {         var testrowselector = "#qunit-test-output-" + details.testid;         var testrow = $(testrowselector);         testrow.append("<button class=\"view\">view graph</button>");         var viewbuttonselector = testrowselector + " button.view";         $(viewbuttonselector).on('click', function(){             // stuff given test name             console.log(details.name);         });     } }); 

Comments