Search code examples
javascriptjqueryurltestingqunit

Click Function Event Test based on URL


How to check whether the click function is opening in correct target and the URL is not broken. I used the below jQuery code for opening a link in a target canvas position, how to do the same as Qunit testing

$(".class_name").click(function (event) {
    event.stopPropagation();
    $("#ad_id").attr({
        src: $(this).attr("href")
    });

Any suggestions is appreciated.


Solution

  • You could use jQuerys trigger method, which simulates an event:

    $(".class_name").trigger('click');
    

    and then check if the src attribute of $("#ad_id") is your expected value.