AngularJS e2e测试:如何获得repeater().count()的值?

前端之家收集整理的这篇文章主要介绍了AngularJS e2e测试:如何获得repeater().count()的值?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
问题

调用转发器(‘#myTable tr’,’Rows’).count();返回Future,而不是整数.我需要获取整数值,以便我可以确认在表中添加了一行.

it('should add a new user when save button is clicked',function()
    {
        showModal();

        //here I'm trynig to store the row count of my table into  a local variable.
        //a future is returned who's 'value' field is undefined.
        var memberCount = repeater('#memberTable tr','Member Rows').count();

        //this outputs 'undefined'
        console.log(memberCount.value);


        input('editedMember.name').enter('John');
        input('editedMember.grade').enter(5);
        input('editedMember.ladderPosition').enter(3);

        element('#saveMemberButton').click();
        sleep(1);
        expect(element(modalId).css('display')).toBe('none');

        //here is where I want to do the comparison against the above stored memberCount
        expect(repeater('#memberTable tr','Member Rows').count()).toBe(memberCount.value + 1);


    });

测试结果

Chrome 25.0 e2e should add a new user when save button is clicked Failed
    expect repeater 'Member Rows ( #memberTable tr )' count toBe null
    /Users/jgordon/learning/chessClub/web-app/test/e2e/scenarios.js:45:3: expected null but was 6
Chrome 25.0: Executed 2 of 2 (1 Failed) (1 min 4.117 secs / 1 min 3.773 secs)
深入研究Angularjs的e2e支持的源代码表明,您必须在Future上调用execute()以使其填充其值.此外,当你调用execute时,你必须为execute()提供一个“done”函数,否则Testacular会(奇怪的是!)跳过你的测试.

var rowCountFuture = repeater('#memberTable tr','Member Rows').count();

        rowCountFuture.execute(function(){
        });

        var memberCount = rowCountFuture.value;

虽然我很高兴看到这个有用,但我担心可能会出现一些异步错误,而且,我觉得这是一个黑客而不是正确的方法.有任何想法吗?

原文链接:https://www.f2er.com/angularjs/240415.html

猜你在找的Angularjs相关文章