首页 > 解决方案 > 在 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 中是否有一种标准的方式来表示相同的内容。

任何帮助,将不胜感激。谢谢。

标签: javascriptjavanode.jstypescripttesting

解决方案


推荐阅读