Jquery trigger() doesnt work in angular scenario test runner in end2end test

旧街凉风 提交于 2019-12-23 02:21:27

问题


I am aware that binding to jquery events in angular "controller" is not in line with this framework philosophy but it allows me to migrate views in asp.net mvc project to angular step by step. This works on runtime but i can't test this. If I have binded jquery event 'keydown' on input field in "controller" and I try to trigger() this event in my test scenario (I am using angular-scenario.js) this event simply is not recieved in "controller". I cant use input().enter() as this input is not part of model (as I said on beginning...). Question: is it possible to trigger event from scenario? If not, should I use different test runner?


回答1:


You can take a look into AngularJS tests. They use browserTrigger(element, 'keydown'); to trigger DOM events on elements.

Here is example from AngularJS source




回答2:


the link above is point to a angular UT rather than e2e case, you may trigger a dom event in e2e via its query api, for example

    element('#something_id').query(function(el, done){
        var evt = document.createEvent('Event');
        evt.initEvent('focus', false, true);
        el[0].dispatchEvent(evt);
        done();
    });


来源:https://stackoverflow.com/questions/14163016/jquery-trigger-doesnt-work-in-angular-scenario-test-runner-in-end2end-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!