How do I trigger a mousemove event in an angularjs unit test

前端 未结 1 1649
滥情空心
滥情空心 2021-01-14 03:51

I have implemented an angularjs directive that use mouse event; clicking on component and moving mouse up or down it can changes a value. So i need to know how do I trigger

相关标签:
1条回答
  • 2021-01-14 04:28

    This blog article shows an example using jqLite's triggerHandler().

    Triggering Events in Angular JS Directive Tests

    EDIT: Okay, I made a Plunker quickly to demonstrate how you can pass parameters too: link. Check the console output to see the parameters on the event object. You can add anything your implementation might need.

    So you can pass data like this for example:

    elem.triggerHandler({
        type : "mousemove",
        pageX: 48,
        pageY: 102
    });
    

    So you will need to get a handle on your element with angular.element and then use above code to trigger events on it.

    0 讨论(0)
提交回复
热议问题