所以我的代码如下所示:
import FsAsyncFactory from '../fs/FsAsyncFactory'
import ObjectHelper from '../utils/ObjectHelper'
import Config from './Config'
export class ConfigHelper {
// this is the function under test
public static async primeCacheObj(): Promise<void> {
const configFileObj: any = await ConfigHelper.getConfigFileObj()
}
private static configCacheObj: Config = null
private static async getConfigFileObj(): Promise<any> {
const fsAsync: any = FsAsyncFactory.getFsAsync()
const fileContents: string = await fsAsync.readFileAsync('./config/hubnodeConfig.json')
return JSON.parse(fileContents)
}
}
export default ConfigHelper
让我的单元测试代码阻止它实际访问磁盘的最佳方法是什么?
我应该使用 InversifyJS 之类的东西来允许依赖注入吗?我有一个初始化脚本,它会在应用程序正常运行时设置“默认值”,然后在测试中“覆盖”这些默认值?