title: Is there a way to mock firebase modules in jest?
body: <p>Code.js</p>
  
  <pre><code>saveToFirebase = () =&gt; {
      let statusMsg = ""
  
      firebase
        .firestore()
        .collection("messages")
        .doc(this.state.field.email)
        .set(this.state.field)
        .then((statusMsg = "Your Message have been submitted successfully."))
  
      this.clearFields(statusMsg)
    }
  </code></pre>
  
  <p>Code.test.js</p>
  
  <pre><code>it("should call mock firebase module", () =&gt; {
              const docData = {
                field: {
                  name: "Rob Bob",
                  email: "rob@bob.com",
                  phone: "9999999999",
                  subject: "Test subject",
                  message: "Test message",
                },
              }
  
              const docResult = {
                data: () =&gt; docData,
              }
  
              const get = jest.fn(() =&gt; Promise.resolve(docResult))
              const set = jest.fn()
  
              const doc = jest.fn(() =&gt; {
                return {
                  set,
                  get,
                }
              })
              const colllection = jest.fn((messages) =&gt; {
                return { doc }
              })
              const firestore = () =&gt; {
                return colllection
              }
  
              firebase.firestore = firestore
  
              const mockData = { fake: "data" }
              jest.clearAllMocks()
              wrapper.instance().saveToFirebase()
            })
  </code></pre>
  
  <p>While running the Code.test.js, it throws an error that firebase.firestore().collection() is not a function. Please suggest proper mocking of the firebase module for the above code and to add a case to check if firebase has successfully returned then, clearFields() is invoked.</p>