angularjs - 如何测试具有多个等待的 AngularJS 控制器方法 - Jasmine?
问题描述
我正在尝试async
通过多个await
调用来测试控制器中的方法,但似乎我遗漏了一些东西。
使用如下设置,await
永远无法解决,不知道为什么。在控制台中,我看到第一个日志,第二个永远不会。当我更新要使用的方法then
而不是await
它时。
// Controller
async asyncMethod()
{
console.log('############################################# 1');
const var1 = await this.customService.getSettings();
console.log('############################################# 2');
// ...
console.log('############################################# 3');
const v2 = await this.customService.getSettings2();
console.log('############################################# 4');
// ...
}
// Test
customService.getSettings = () => { return $q.resolve(true); };
customService.getSettings2 = () => { return $q.resolve(true); };
describe('asyncMethod', function () {
it('should call asyncMethod', function (done) {
controller.asyncMethod();
$rootScope.$digest();
// expect statements
// ...
});
});
解决方案
推荐阅读
- go - 如何使用 OpenAPI Generator Client SDK 访问 HTTP 错误正文
- c# - 命令行参数和“字节”数组
- php - 将变量从一页传递到表单
- azure - 从 cosmosDB 文档的嵌套数组中删除数据
- python - 将类对象作为引用参数传递
- eclipse - 在 Eclipse 首选项中配置 maven 原型后,我的磁盘空间不足
- node.js - 如何从 mongodb 的子集合中获取数据?
- javascript - 如何使用 javascript/jquery 使用动态 json 数据无缝显示进度
- javascript - 捕获 FullCalendar4 点击日期数字事件
- python - 数据框切换日期开始星期日期从星期六开始