vendredi 31 août 2018

Google Cloud Functions test with mocha - stubbing firebase instance problem

I'm creating my mocha tests using sinon for stubbing just as recommended in official docs.

I have my functions splitted in different files. For this question let's assume I only have one: userSignup. So the file structure would be like this:

functions // root folder
  src
    index.ts // all function exports
    app.ts // Firebase instantiation
    userSignup.ts // Cloud function
  tests
    index.spec.ts // tests file (will be splitted later)

This is the code of the index.spec.ts: https://pastebin.com/qZDgZ8gK

The problem is that, the first test passes correctly and the second doesn't because adminInitStub is using the same commit result from the previous test's firebaseObject, so it's expecting an "ok" again.

I tried by stubbing initializeApp inside a beforeEach and also using afterEach to restore/clear everything. Didn't work.

What am I missing here?

Aucun commentaire:

Enregistrer un commentaire