how to change jest mock function return value in each test?

前端 未结 3 1677
暗喜
暗喜 2020-12-23 11:29

I have a mock module like this in my component test file

  jest.mock(\'../../../magic/index\', () => ({
    navigationEnabled: () => true,
    guidance         


        
3条回答
  •  梦毁少年i
    2020-12-23 11:50

    what you want to do is

    import { navigationEnabled, guidanceEnabled } from '../../../magic/index';   
    
    jest.mock('../../../magic/index', () => ({
      navigationEnabled: jest.fn(),
      guidanceEnabled: jest.fn()
    }));
    
    describe('test suite', () => {
      it('every test', () => {
        navigationEnabled.mockReturnValueOnce(value);
        guidanceEnabled.mockReturnValueOnce(value);
      });
    });
    

    you can look more about these functions here =>https://facebook.github.io/jest/docs/mock-functions.html#mock-return-values

提交回复
热议问题