I have a html view which contains a div with class “overlay” and a close button with class “close-overlay”. I have events registered in JS for them like this :
$(".overlay").click(function(e){
var target = $(this); // overlay div
target.removeClass("hide");
return target;
});
$(".close-overlay").click(function(e){
var target = $(e.target) // close-overlay btn
.closest(".overlay"); // overlay div
target.addClass("hide");
return target;
});
and I’ve tests in qunit as below :
test("Basic Test", function(){
equal($(".overlay").click().hasClass("hide"), false, "Overlay Click" );
equal($(".close-overlay").click().hasClass("hide"), true, "Overlay Hide" );
});
The first test is getting passed , but the second one is getting failed. Have no idea why !
Could someone please help ? Thanks.
In your second assertion, you are testing that the
.close-overlayelement has the hide class instead of the.overlayelement.So your test should be: