So my code looks like this:
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
What's the best way to allow my unit testing code to stop it from actually hitting the disk?
Should I be using something like InversifyJS to allow dependency injection? I'd have an init script that would setup the "defaults" for when the app is running normally then "override" those defaults in the tests?