AngularJS Jasmine测试有没有wait()函数?

时间:2015-06-04 06:51:36

标签: angularjs unit-testing jasmine

我创建了一个弹出窗口,它会在第一次点击时打开,并在第二次点击时关闭。但是,我在测试时遇到了问题。第二次单击不会关闭弹出窗口。我发现问题是因为在第一次点击期间弹出窗口还没有出现在屏幕上,这就是为什么第二次点击不会关闭弹出窗口。所以,我决定在点击之间加上延迟。关于如何实施延迟的任何想法?

<!DOCTYPE html>
<html lang="en-US">
    <head>
        <meta charset="utf-8">
    </head>
    <body>
        <p>
            {{ $msg }}
        </p>
    </body>
</html> 

1 个答案:

答案 0 :(得分:2)

您需要的是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();将等到它完全响应前面