我如何在我的量angular器testing中使用lodash _.find?
我想使用Lodash find
function,使我的量angular器testing更健壮。
代替
element.all (by.repeater ('topic in topics')).then (function (topics) { expect (topics[1].element (by.binding ('topic.name')).getText()).toEqual ('Maths'); expect (topics[1].element (by.binding ('topic.description')).getText()).toEqual ('2 + 2 = 4'); });
就像是
element.all (by.repeater ('topic in topics')).then (function (topics) { var mathsTopic = _.find (topics, 'topic.name', 'Maths'); expect (mathsTopic.element (by.binding ('topic.description')).getText()).toEqual ('2 + 2 = 4'); });
我的推理是,如果页面中的项目顺序发生变化,testing不会中断,因为它仍然可以find正在查找的数据的元素。
你几乎明白了:
var mathsTopic = _.find(topics, { name: 'Maths' });
这可以理解为:find我的第一个主题的名称属性等于“math”的话题。
你有没有尝试使用filter
?
var topic = element.all(by.repeater('topic in topics')) .filter(function (row) { return row.element(by.binding('topic.name')).getText().then(function(name) { return name === 'Maths'; }); }) .first() .map(function(row) { return { name: row.element(by.binding('topic.name')).getText()), description: row.element(by.binding('topic.description')).getText()) }; }); expect(topic).toEqual({ name: 'Maths', description: '2 + 2 = 4' });
- 安装Chrome个人资料的扩展程序 量angular器
- 量angular器configuration文件:cucumberOpts标签不单独采取或忽略
- 量angular器插件 – 辅助function – AssertionError:path必须是一个string
- 是否有可能更改量angular器事件队列或控制stream?
- 如何查看在Angular中声明的node_modules的非缩小的源文件
- Angular命令问题 – 即使在PATH环境variables中,“ng”命令也不会被识别为内部或外部命令
- 为什么有些软件包不能在angular度2安装时进入供应商文件夹
- Angular 2快速入门 – 我的应用程序组件不加载
- 错误TS2307:找不到模块'bluebird'