Skip to content

Instantly share code, notes, and snippets.

@dancourse
Created May 19, 2014 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dancourse/45ad644fe6d4cc55c209 to your computer and use it in GitHub Desktop.
Save dancourse/45ad644fe6d4cc55c209 to your computer and use it in GitHub Desktop.
DalekJS: Custom `hasClass` method
// _addNewFunc is just a function that adds this to the main DalekJS test at run-time
_addNewFunc("hasClass", function (__selector, __needle)
{
// generate a random name for this element
var name = "hasClass-" + new Date().getTime(),
nameElem = "span#"+name;
return this.dse_self
.execute(function(__selector, __needle, __name)
{
// create a new element to house the result
var newELEM = $('<span />').attr('id', __name).attr("data-has-class", "false");
$("body").append(newELEM);
// use jquery to test if the class exists
if($(__selector).hasClass(__needle))
{
// it exists, change the value
$(newELEM).attr('data-has-class', 'true');
}
}, __selector, __needle, name)
// test the elem if the data is true
.assert.attr(nameElem, 'data-has-class', 'true', __selector + " has the class, " + __needle)
// cleanup
.execute(function(__nameElem)
{
$(__nameElem).remove();
}, nameElem);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment