Simulate Hover in jQuery
javascript, jquery, konacha
Solution
Try `mouseenter` and `mouseleave`
$('.someClass li:first').mouseenter().mouseleave();
From jQuery docs
Calling `$(selector).hover(handlerIn, handlerOut)` is shorthand for: `$(selector).mouseenter(handlerIn).mouseleave(handlerOut);`
DEMO: http://jsfiddle.net/skram/wh5N9/
Try below to check for an class that would have added in hover
$("#test").mouseenter(function() {
console.log('Has class hover ' + $(this).hasClass('ui-state-hovered'));
}).mouseleave(function() {
console.log('Has class hover ' + $(this).hasClass('ui-state-hovered'));
})
Make sure the above is registered after `.hover`
DEMO: http://jsfiddle.net/skram/wh5N9/2/
Problem
Currently, I have some jQuery/Javascript code that toggles the css class 'ui-state-hovered' when a user hovers the mouse over certain elements, and I want to write a test in konacha to test this piece of code. How would I write this function in Javascript with the help of jQuery? Return true if when a user hovers over an element $('.someClass li:first'), the class 'ui-state-hovered' exists. Else return false. How would I simulate a user hovering their mouse over that element?