title: How to check if a method is called in nested jest mock functions
body: <p>I have a mock service like below</p>
  
  <pre class="lang-js prettyprint-override"><code>  const firebaseService = jest.fn(() =&gt; ({
      initializeApp: jest.fn(() =&gt; { /*do nothing*/}),
    }))
  </code></pre>
  
  <p>in my test I want to <code>expect</code> if <code>initializeApp</code> has been called.
  How can I check that?</p>
  
  <pre class="lang-js prettyprint-override"><code>it('should be called', () =&gt; {
     expect(???).toHaveBeenCalledTimes(1);
  });
  </code></pre>
  
  <h2>Update : Real scenario</h2>
  
  <pre><code>  const collection = jest.fn(() =&gt; {
      return {
        doc: jest.fn(() =&gt; {
          return {
            collection: collection,
            update: jest.fn(() =&gt; Promise.resolve(true)),
            onSnapshot: jest.fn(() =&gt; Promise.resolve(true)),
            get: jest.fn(() =&gt; Promise.resolve(true))
          }
        }),
        where: jest.fn(() =&gt; {
          return {
            get: jest.fn(() =&gt; Promise.resolve(true)),
            onSnapshot: jest.fn(() =&gt; Promise.resolve(true)),
            limit: jest.fn(() =&gt; {
              return {
                onSnapshot: jest.fn(() =&gt; Promise.resolve(true)),
                get: jest.fn(() =&gt; Promise.resolve(true)),
              }
            }),
          }
        }),
        limit: jest.fn(() =&gt; {
          return {
            onSnapshot: jest.fn(() =&gt; Promise.resolve(true)),
            get: jest.fn(() =&gt; Promise.resolve(true)),
          }
        })
      }
    });
  
    const Firestore = {
      collection: collection
    }
  
      firebaseService = {
        initializeApp() {
          // do nothing
        },
        firestore: Firestore
      };
  </code></pre>
  
  <p>and I want to check below</p>
  
  <pre><code> expect(firebaseService.firestore.collection).toHaveBeenCalled();
   expect(firebaseService.firestore.collection.where).toHaveBeenCalled();    
   expect(firebaseService.firestore.collection.where).toHaveBeenCalledWith(`assignedNumbers.123`, '==', true);
  </code></pre>