Testing jQuery Hover with Jasmine

How do I go for testing the action of jQuery Hover with Jasmine? My jQuery looks like

$('.class').hover(
  function() { $('#someid').hide(); },
  function() { $('#someid').show(); }
);

How did I simulate the movement of the hover action with jasmine and expect the "someid" element to be hidden and shown as it should?

+5
source share
1 answer

You should be able to directly trigger the mouseover event, and then check the appropriate behavior:

it("should do something on hover", function() {
  $('.class').trigger('mouseover');
  expect($('#someid')).toBeHidden();
  $('.class').trigger('mouseout');
  expect($('#someid')).toBeShown();
});

$('#someid')must be in the DOM. The best way to do this is through adaptation.

+12
source

All Articles