title: Unit testing firebase functions: how to stub firebase-admin sdk
body: <p>In index.js, I have the following</p>
  
  <pre><code>exports.write = functions.https.onRequest((req, res) =&gt; {
      admin.database()
          .ref(`xxx/yyy`)
          .push()
          .set({timestamp: admin.database.ServerValue.TIMESTAMP});
      res.status(200).end();
  });
  </code></pre>
  
  <p>In my test.js, I stub admin.database() as follows:</p>
  
  <pre><code>const refStub = sinon.stub();
  setStub = sinon.stub();
  refStub.withArgs('xxx/yyy').returns({push: () =&gt; ({key: 'fakeKey', set: setStub})});
  databaseStub = sinon.stub(admin, 'database').get(() =&gt; {
      return () =&gt; {
        return {ref: refStub};
      };
    });
  </code></pre>
  
  <p>When I run my test, I get the following error <code>TypeError: Cannot read property 'TIMESTAMP' of undefined</code>.  How do I fix this error or stub the call to <code>admin.database.ServerValue.TIMESTAMP</code>? Thanks.</p>