首页 > 解决方案 > 模拟 window.URL.createObjectURL 时的 typescript-eslint/unbound-method

问题描述

我正在尝试让我的单元测试正常工作。它目前失败:

TypeError: URL.createObjectURL is not a function

我最终偶然发现:

所以我现在提供以下模拟:

  test('my test', async (): Promise<void> => {
    window.URL.createObjectURL = (object: any): string => object.toString();

然而,这使得 eslint 报告现在:

Avoid referencing unbound methods which may cause unintentional scoping of `this`.

即使读了两遍:

感觉(object: any): string => object.toString()这里是对的。我错过了什么/误解了什么?

标签: typescriptjestjseslint

解决方案


推荐阅读