title: How to use nock in order to mock Firebase/Firestore in NodeJS?
body: <p>I have a REST API which written in NodeJS. The REST API gets a file and information and then uploads the file to the drive and stores the information inside my Firebase/Firestore DB. I'm trying to write tests in order to test my REST API, so I need to mock Firestore. I already mock the google-drive using <code>nock</code> by tracking the HTTPS requests that are made by <code>googleapis</code>. Now I'm trying to do the same thing with Firestore.</p>
  <p>I tried different methods like, for example, for authentication I tried (<a href="https://cloud.google.com/firestore/docs/reference/rest" rel="nofollow noreferrer">based on the docs</a>):</p>
  <pre><code>nock('https://firestore.googleapis.com/$discovery/rest')
  .persist()
  .post('')
  .reply(200, { 'access_token': 'abc', 'refresh_token': '123', 'expires_in': 10 })
  </code></pre>
  <p>But nock does not follow the requests. How do I use nock to track the following code? Does <code>firebase</code> package actually makes requests to the API?</p>
  <pre><code>const firebase = require(&quot;firebase&quot;);
  
  // Required for side-effects
  require(&quot;firebase/firestore&quot;);
  
  // First code - authenatiocation
  firebase.initializeApp(firebaseConfig);
  db = firebase.firestore();
  
  // ...
  // Second code - Get data from DB
  const snapshot = await db.collection(collection).orderBy(&quot;timestamp&quot;, &quot;desc&quot;).get();
  
  // ...
  // Third code - upload new report
  const response = await db.collection(collection).doc(document_id).set(data);
  </code></pre>
  <p>If it's not possible with <code>nock</code>, then it can be achieved?</p>