Is there any wait() function for AngularJS Jasmine test?

你说的曾经没有我的故事 提交于 2019-12-13 04:55:59

问题


I created a popup, it will open on first click and will close on second click. However, I faced problem when do testing. The second click doesn't close the popup. And I found out that the problem is because during the first click the popup haven't appeared in the screen yet, that's why the second click doesn't close the popup. So, I decide to put a delay between the clicks. Any idea on how to implement the delay?

describe('Popup', function(){
            it("Should close on second click", function(){
                compileDirective(400,'click','true');  
                element.triggerHandler('click');
                waitttttttt(1000); // Wait function here before proceed to next line
                element.triggerHandler('click');
                scope.$digest();
                timeout.flush();
                expect($('.sidepopright').length).toBe(0);
                element.remove();
                $(".sidepopright").remove();
            });
      });

回答1:


what you need is browser.waitForAngular();

describe('Popup', function(){
            it("Should close on second click", function(){
                compileDirective(400,'click','true');  
                element.triggerHandler('click');
                browser.waitForAngular(); // Wait function here before proceed to next line
                element.triggerHandler('click');
                scope.$digest();
                timeout.flush();
                expect($('.sidepopright').length).toBe(0);
                element.remove();
                $(".sidepopright").remove();
            });
      });

browser.waitForAngular(); will wait till it gets the full response to the front



来源:https://stackoverflow.com/questions/30636916/is-there-any-wait-function-for-angularjs-jasmine-test

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