gpt4 book ai didi

AngularJS e2e 测试 : How To Get value of repeater(). count()?

转载 作者:行者123 更新时间:2023-12-04 14:30:32 25 4
gpt4 key购买 nike

问题

调用repeater('#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 支持的源代码表明您必须调用 execute()Future让它填充它的值。此外,当您调用 execute您必须为 execute() 提供“完成”功能否则 Testacular 将(奇怪的是!)跳过你的测试。
代码

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

rowCountFuture.execute(function(){
});

var memberCount = rowCountFuture.value;
虽然我很高兴看到这个作品,但我担心可能会出现一些异步错误,而且,我觉得这是一个 hack,而不是正确的方法。有任何想法吗?

关于AngularJS e2e 测试 : How To Get value of repeater(). count()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14567018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com