javascript - 在 Typescript 或 JavaScript 中使用类似于 @VisibleForTesting 注释的任何东西?
问题描述
通过 Google Guava 库在 Java 中提供了一个@VisibleForTesting
注解,表明类型或成员的可见性已放宽以使代码可测试:注解使私有方法仅对测试类公开。随后还有一些插件可以确保被注释的方法@VisibleForTesting
实际上只在测试类中使用。
我目前有一个打字稿接口,我必须在接口中添加一些方法,只是为了测试目的。例如:
interface ProcessorInterface {
process(data: Readonly<Data>): Promise<Result>;
// these 2 methods are only added here so that they are
// callable from the implementation while writing tests.
processBatch(data: Readonly<Data>): Promise<Result>;
validate(data: Readonly<Data>): Promise<Error[]>;
}
我想知道 Typescript 中是否有一种标准的方式来表示相同的内容。
任何帮助,将不胜感激。谢谢。
解决方案
推荐阅读
- c++ - scanf() 语句中的格式字符串“%*[^\n]”有什么指示?分配抑制器 (*) 和否定扫描集 ([^) 如何协同工作?
- bash - sed remove trailing slash from url
- android - Android HERE SDK - 示例应用未替换 app_id 和 app_code
- excel - VBA在插入单元格时更改数字十进制数
- c# - Unity:动画事件不会改变动画对象的变换
- bluetooth - 多个连接上的蓝牙 5 和 BLE 吞吐量
- python - 如何在按钮内获取html元素?
- java - 将 JSON 字符串映射到 HashMap
- php - Laravel 5.7 中的 auth 和 access 有什么区别?
- python - 如何使用 Pandas 从某个时间戳获取 date_range?