Jest mocking reference error

前端 未结 2 1760
你的背包
你的背包 2021-02-13 12:04

I\'m trying to use the following mock:

const mockLogger = jest.fn();

jest.mock(\"./myLoggerFactory\", () => (type) => mockLogger);

but m

2条回答
  •  春和景丽
    2021-02-13 12:39

    I want to improve last answer with an example of code working:

    import { getCookie, setCookie } from '../../utilities/cookies';
    
    jest.mock('../../utilities/cookies', () => ({
      getCookie: jest.fn(),
      setCookie: jest.fn(),
    }));
    // Describe(''...)
    it('should do something', () => {
        const instance = shallow().instance();
    
        getCookie.mockReturnValue('showMoreInfoTooltip');
        instance.callSomeFunc();
    
        expect(getCookie).toHaveBeenCalled();
    });
    

提交回复
热议问题