如何找到[(ngModel)]用于量角器测试 [英] How to locate [(ngModel)] for protractor tests

查看:59
本文介绍了如何找到[(ngModel)]用于量角器测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<span class="selector-label">Team: </span>
<select class="selector-component" [(ngModel)]="selectedTeamId">
  <option *ngFor="#team of teams" [value]="team.id">{{team.name}}</option>
</select>

我正在尝试为selectedTeamId添加量角器测试,这是第一个按字母顺序排序的测试(如果有一个用户分配的话)到多个团队。我认为我应该使用[(ngModel)] = selectedTeamId,但不确定如何执行此操作。谢谢。
我知道如何组建所有团队,但我需要获得第一个团队,这是在selectedTeamId方法中实现的逻辑。

I am trying to add protractor tests for the selectedTeamId which is the first one sorted alphabetically if one user assigned to multiple teams. I think I should use [(ngModel)]="selectedTeamId", but not sure how to do it. thanks. I know how to get all teams, but I need to get the first one which is the logical implemented in selectedTeamId method.

推荐答案

想法是找到 select 元素(通过例如前面的标签),评估 团队按字母顺序将其名称,获得第一支队伍,并检查其是否与 selectedTeamId 模型值相同:

The idea would be to locate the select element (by the preceding label, for example), evaluate teams, sort it alphabetically by name, get the first team and check that this is the same as the selectedTeamId model value:

var select = element(by.xpath("//span[starts-with(., 'Team')]/following-sibling::select"));

select.evaluate("teams").then(function(teams) {
    teams.sort(function(a, b) {
         return a["name"].localeCompare(b["name"])
    });
    var firstTeam = teams[0];

    expect(select.evaluate("selectedTeamId")).toEqual(firstTeam);
});

这篇关于如何找到[(ngModel)]用于量角器测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆