Jest mock inner function

后端 未结 5 2428
清歌不尽
清歌不尽 2020-11-28 06:49

I have one file called helper.js that consist of two functions

export const funcA = (key) => {
   return funcB(key)
};

export const func         


        
5条回答
  •  情话喂你
    2020-11-28 07:31

    I create a kind of nameSpace to handle this issue:

    let helper = {}
    
    const funcA = (key) => {
       return helper.funcB(key)
    };
    
    const funcB = (key,prop) => {
        return someObj;
    };
    
    helper = { funcA, funcB }
    
    module.exports = helper
    

    and then mocking is obvious with jest.fn

提交回复
热议问题