Jest mock inner function

后端 未结 5 2424
清歌不尽
清歌不尽 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:27

    import * as helper from 'helper';
    
        describe('helper', () => {
           it('should test testFuncA', () => {
              const mockTestFuncB = jest.mock();
              // spy on calls to testFuncB and respond with a mock function
    
               mockTestFuncB.spyOn(helper, 'testFuncB').mockReturnValue(/*your expected return value*/);
    
              // test logic
    
              // Restore helper.testFuncB to it's original function
              helper.testFuncB.mockRestore();
           }
        }
    

提交回复
热议问题