How to mock specific function in object using Jest?

后端 未结 2 1734
情歌与酒
情歌与酒 2020-12-31 18:41

I\'m testing a React/Reflux application using Jest. I have the following function in a store:

onLoad: function() {
  c         


        
2条回答
  •  离开以前
    2020-12-31 19:16

    I have found jest mock instance function It's here

    eg:

    import expect from 'expect';
    
    jest.mock('../libs/utils/Master');
    import Master from '../libs/utils/Master';
    
    Master.mockImplementation(() => {
      return {
        returnOne: jest.fn().mockReturnValueOnce(1)
      }
    })
    describe('test Master', function() {
      it('test search', function() {
        let master = new Master();
        expect(master.returnOne()).toEqual(1);
      });
    });
    

提交回复
热议问题