小编hea*_*kit的帖子

测试Android辅助功能服务?

我正在开发一个带有扩展服务的Android应用程序AccessibilityService.我希望能够在不模仿可访问性框架的情况下进行测试.

有没有人对最佳方法有一些建议?

我想设置一些不同的活动,在它们之间移动,并验证我的辅助功能服务是否正确响应.我尝试使用a ServiceTestCase,但不幸的是,这需要您自己设置服务.我不确定如何以类似于可访问性框架为我设置它的方式进行设置.

testing android accessibility android-a11y

8
推荐指数
1
解决办法
1074
查看次数

在 TypeScript 中使用 async/await 链接方法

我有一种情况,我需要对异步方法的结果调用异步方法。

class Parent {
  constructor(private child: Child) { }

  private getChild(): Promise<Child> {
    return Promise.resolve(this.child);
  }

  async getResult(): Promise<Child> {
     return await this.getChild()
  }
}

class Child {
  getText(): Promise<string> {
    return Promise.resolve('text');
  }
}

let child = new Child();
let container = new Parent(child);

let printText = async () => {
  await (await container.getResult()).getText();
}

printText();
Run Code Online (Sandbox Code Playgroud)

有没有一种好方法可以避免双重等待的需要?我想我只想做await container.getChild().getText();。在 TypeScript 中创建 API 的正确方法是什么,它允许我链接返回 promise 的方法,然后通过一个 await 等待结果?

编辑:澄清一下,这更像是一个 API 设计问题。有没有更好的模式来做我想做的事情(在异步方法返回的对象上调用异步方法)?即使这意味着做一些完全不同的事情?

javascript asynchronous promise async-await typescript2.0

6
推荐指数
1
解决办法
4718
查看次数