I’m using moo4q+jquery, with qUnit+sinon test framework.
Currently to trigger a click event, I have done the following:
object.jThis.click(); // simulate a click event
Where object.jThis is the jQuery object (wrapper set) the object maps to.
For me the issue is that other events such as .hover() do not trigger an event the same way as .click().
Is this just an inconsistency in jQuery’s API?
EDIT:
// wire up event
attach: function() {
this.jThis.hover(function(eventObj) {
this.proxied.showOptionsProxy(true);
}, function() {
this.proxied.showOptionsProxy(false);
});
}
// unit test:
test("Test_hover_shows_menu", 2, function() {
var target = this.getTarget();
this.spy(target.proxied, 'showOptionsProxy');
target.detach(); // must detach only for unit test after setting up spy on the proxy
target.attach();
target.jThis.mouseenter();
ok(target.proxied.showOptionsProxy.calledWith(true), "hovering over options button shows the menu");
target.jThis.mouseleave();
ok(target.proxied.showOptionsProxy.calledWith(false), "mousing away from options button hides menu");
});
hover()is not an event but sugar for.on( "mouseenter mouseleave"), you can trigger hover by triggering.mouseenter()for the entering phase, and.mouseleave()for the leaving phaseSee: http://api.jquery.com/hover/
Demo: http://jsfiddle.net/2ZLMJ/