How do you mock Firebase Firestore methods using Jest?

前端 未结 7 1778
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-17 17:12

I have a series of functions, each performing various firestore interactions. How do I use Jest to mock these firestore calls? I would like to avoid using a library.

7条回答
  •  醉酒成梦
    2020-12-17 17:57

    I found that mocking the import works well. I added this code in the test, above where I render my component importing 'firebase/app'

    jest.mock('firebase/app', () => ({
      __esModule: true,
      default: {
        apps: [],
        initializeApp: () => {},
        auth: () => {},
      },
    }));
    

提交回复
热议问题