angular - 在功能测试中链接 Promises/Observable 的最优雅方式
问题描述
这是我正在处理的项目中现有测试的示例:
AppPage.lastnameInput().clear().then(function () {
AppPage.lastnameInput().sendKeys(lastname).then(function () {
AppPage.firstnameInput().clear().then(function () {
AppPage.firstnameInput().sendKeys(firstname).then(function () {
AppPage.ibanInput().clear().then(function () {
AppPage.ibanInput().sendKeys(IBAN).then(function () {
$('body').click().then(function () {
callback();
});
});
});
});
});
});
});
在我看来,这可能会变平。就像是 。
foo(
AppPage.lastnameInput().clear(),
AppPage.lastnameInput().sendKeys(lastname),
AppPage.firstnameInput().clear(),
AppPage.firstnameInput().sendKeys(firstname),
AppPage.ibanInput().clear(),
AppPage.ibanInput().sendKeys(IBAN),
$('body').click(),
).then(() => callback())
我试过forkJoin()
了,但似乎在执行下一个 Observable 之前它不会等待第一个 Observable 完成。
我可以自己实现这样的功能,但它看起来很通用,所以我想知道是否已经存在更标准的功能。
解决方案
您可以使用该concat()
函数按顺序执行多个可观察对象(而不是并行执行forkJoin()
)。
推荐阅读
- java - 图像不会从 MySQL 数据库加载到我的 JSP 页面中
- python - 对象之间的 Python Pygame 碰撞检测
- tmux - 有没有办法只在 tmux 中列出当前会话的窗口?
- python - Django 有时不会在删除时级联
- angular - Angular 2.调用组件并获取参数只工作一次
- c++ - 为什么不能取消引用指向 const 对象的 const 指针的 const 指针来调用 const 对象中的成员函数?
- android - Firebase App Distribution APK 不会安装
- javascript - 使用 node.js 和 express 列出待办事项
- c++ - 如果我使用 new 创建向量并将它们放在向量中,外部向量或内部向量析构函数会删除它们吗?
- slurm - Slurm:默认分配一定数量的 GPU