dimanche 1 février 2015

Finding a child of a HTMLCollection by attribute value

Within a unit test for an angular directive, I want to inspect the DOM that has been compiled:



var element = $compile("<div pr-sizeable='...'></div>")($rootScope);
var children = element[0].children; // HTMLCollection

expect(children.length).toBeGreaterThan(0); // that's fine


Especially, I want to check for the existence of a specific child element having an attribute pr-swipe-handler='right'.


I know I could iterate the children and their attributes-collections, but I'm sure there is a more tense solution.


Here's what I tried (refering to this answer of a similar post):



// TypeError: angular.element(...).querySelector is not a function
angular.element(children).querySelector("[pr-swipe-handler='right']")

// TypeError: children.querySelector is not a function
angular.element(children.querySelector("[pr-swipe-handler='right']"))

Aucun commentaire:

Enregistrer un commentaire