我想测试添加到列表中的项目是否具有某种值(value)。我当前的测试如下:
containerDetail.openItemAddModal();
element(by.css('[ng-click="form.section = \'batch\'"]')).click();
element(by.model(batchModel)).sendKeys(batchEntry); // we insert the batch items here
element(by.buttonText('Add')).click();
expect(element.all(by.repeater('item in detail.container.items')).count()).toEqual(6);
// Would like to test that each item has some text
// thinking something like this:
element.all(by.repeater('item in detail.container.items')).each(function(item) {
item.getText().then(function(text) {
expect(text).toBeTruthy();
});
});
我一直在谷歌上搜索执行此操作的好方法,但没有想出任何办法。
最佳答案
each()
非常适合这里。我会使用来自 jasmine-matchers
的 toBeNonEmptyString()
匹配器断言有一个非空文本:
element.all(by.repeater('item in detail.container.items')).each(function(item) {
expect(item.getText()).toBeNonEmptyString();
});
此外,如果您知道添加到列表中的预期值,您可以使用 map()
:
var items = element.all(by.repeater('item in detail.container.items')).map(function (item) {
return item.getText();
});
expect(items).toEqual(["Value 1", "Value 2", "Value 3", "Value 4", "Value 5", "Value 6"]);
关于javascript - 测试列表中的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30334116/