Looking to mock certain functions within a function I'm currently testing.
In my code, there is a class with various static private functions that are called by the main function. Specifically, I want to verify the output of MyClass.functionD (which is invoked by mainFunction, a private method). To do this, I aim to mock MyClass.functionA, MyClass.functionB, and MyClass.functionC to return default results, allowing me to focus on the outcome of MyClass.functionD in my test.
export default class MyClass {
static mainFunction(paramA: string, paramB: number): boolean {
if (MyClass.functionA(paramA, paramB)) {
return false;
}
if (!MyClass.functionB(paramA, paramB)) {
return false;
}
if (MyClass.functionC(paramA, paramB)) {
return false;
}
// Need to concentrate on the result of this private function for testing
if (MyClass.functionD(paramA)) {
return false;
}
return true;
}
}
I've experimented with jest spyOn and default mock functions but feel stuck due to my limited experience with TypeScript/Javascript. Any pointers or references on how to proceed would be greatly appreciated! Thanks in advance.