Hys*_*ter 5 unit-testing typescript jestjs
我正在处理旧环境,并且我有包含模块或/和类的 Typescript 文件
class SomeClass {
...
}
module AndAModule {
export namespace NestedNamespace {
...
}
}
Run Code Online (Sandbox Code Playgroud)
注意顶级模块/类中缺少“export”关键字。
我想使用 Jest 库测试“NestedNamespace”中的函数。但是,当我在测试文件中导入 Typescript 文件时:
var service = require("/path/to/file/SomeService.ts")
Run Code Online (Sandbox Code Playgroud)
我无法访问 SomeService.ts 文件中定义的类或模块。如果在模块和类之前添加“export”关键字,我可以通过从 require 返回的对象访问它们,但是这会破坏整个环境和其他文件,因为在此之后,模块和类不存在于生成的 outFile 中通过打字稿。
如何从文件中导入所需的模块,而不添加任何导出语句?
| 归档时间: |
|
| 查看次数: |
952 次 |
| 最近记录: |