I want to mock some functions within a function, I am testing. I have a class that has several static private functions being called from one so-called mainFunction
. I want to particularly test the result of MyClass.functionD
(called by mainFunction
) which is a private method, therefore, I would like to mock MyClass.fucntionA
, MyClass.fucntionB
and MyClass.fucntionA
to return a default result so that my test can focus on the result of MyClass.fucntionD
.
export default class MyClass { static mainFunction(paramA: string, paramB: number): boolean { if (MyClass.fucntionA(paramA, paramB)) { return false; } if (!MyClass.fucntionB(paramA, paramB)) { return false; } if (MyClass.fucntionC(paramA, paramB)) { return false; } // I need to focus on the result of this function (i.e. private) for my test if (MyClass.fucntionD(paramA)) { return false; } return true; } }
So far, I have tried jest spyOn
and some default mock function but I am just lost and cannot proceed as I am really new to typescript / Javascript. Any hint/reference related to how I should proceed would be enough for me. :) Thanks.
from Recent Questions - Stack Overflow https://stackoverflow.com/questions/65376946/mock-static-functions-called-in-the-main-function-that-is-being-tested Intesar Haider
没有评论:
发表评论