我正在尝试测试我们的DataStudio
代码(在Typescript中),它使用了google-apps-script库中的某些接口,例如Logger
和DataStudio
接口。这些文件驻留在.d.ts
文件中,所以我不能轻松地导入它们。下面是在google-apps-script.base.d.ts
文件中定义Logger
的方式:
/// <reference path="google-apps-script.types.d.ts" />
declare namespace GoogleAppsScript {
export module Base {
[...]
export interface Logger {
clear(): void;
getLog(): string;
log(data: Object): Logger;
log(format: string, ...values: Object[]): Logger;
}
}
}
declare var Logger: GoogleAppsScript.Base.Logger;
我正在使用这些接口的函数上运行jest测试,但是我接收到了例如Logger is not defined
,所以我需要以某种方式模拟这些接口。
有人知道如何导入这些接口以便模拟它们吗?谢谢你的帮助!
发布于 2020-02-05 07:42:23
参见Mocking globals in Jest。例如,要模拟控制台,您可以在测试文件的顶部包含以下内容:
global.Logger = jest.fn(console.log)
https://stackoverflow.com/questions/59751316
复制相似问题