jeudi 31 mars 2016

DOM access methods to get DOM coverage of JavaScript unit tests

It is surprising that there is no DOM coverage tool for JavaScript unit tests. I'm trying to implement DOM coverage for my research. The following code modifies the prototype of 'getElementById' and saves the accessed element to an array. Then, I can know which DOM elements are covered when executing JavaScript unit tests.

var gebi = Document.prototype.getElementById;
Document.prototype.getElementById= function(id) {
  var r= gebi.call(this,id);
  return saveAndReturnEle(r);
}

var accessedElements=[];
function saveAndReturnEle(elem){
   accessedElements.pushIfNotExist(elem,function(e){
     return e === elem;
   });
   return elem;
}

I would like to know what methods I should modify like above to get the DOM coverage of modern Web applications. I'm not sure that modifying following methods are enough.

document.getElementById(id)
document.getElementsByClassName(className)
document.getElementsByTagName(tagName)
document.querySelector(cssSelector)
document.querySelectorAll(cssSelector)

Aucun commentaire:

Enregistrer un commentaire