When setting up my test suite, I used the following approach to mock a class method:
beforeEach(() => {
jest
.spyOn(MyClass.prototype, "loadVars")
.mockImplementation(async () => {
const file:string = `MyClass.${
this.prefix // <---- how can I address this?
}.data.mock.json`;
logger.info(`Mocking all parameters from ${file}`);
return JSON.parse(
fs.readFileSync(
process.cwd() + `/../data/${file}`,
"utf-8"
)
);
});
});
Is there a way to reference the current instance of the class within this mock function?