我如何在我的量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' });
- 使用npm install angular2 –save时出错
- 如何使用“内容types”:“application / x-www-form-urlencoded”发布Post请求?
- 平均应用程序。 同时两台服务器Express,NodeJS,Angular 2
- ./ClientApp/boot.server.ts中的错误找不到模块:错误:无法parsing'./../$$_gendir/ClientApp/app/app.server.module.ngfactory'
- 为什么会得到“TypeError:Reflect.getOwnMetadata不是一个函数”
- 错误TS7027:在Angular2 TypeScript Service类中检测到无法访问的代码
- 在Angular(> = 2)应用程序中,如何将版本信息从npm package.json文件包含到已编译的输出文件中?
- Angular2和express node.d.ts冲突
- 无法从另一个文件夹访问我的.scss软件包文件