Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic online test case doesn't work #45

Closed
garrettg123 opened this issue Jul 30, 2019 · 2 comments
Closed

Basic online test case doesn't work #45

garrettg123 opened this issue Jul 30, 2019 · 2 comments

Comments

@garrettg123
Copy link

garrettg123 commented Jul 30, 2019

Version info

firebase-functions-test: 0.1.6

firebase-functions: 3.2.0

firebase-admin: 8.2.0

Test case

import path from 'path'

// Set up Firebase Functions Test
const settings = {
  databaseURL: 'https://X.firebaseio.com',
  storageBucket: 'X.appspot.com',
  projectId: 'X',
}
const serviceAccountKeyPath = path.resolve(
  __dirname,
  'firebase-adminsdk-service-account-key.json'
)
const firebaseFunctionsTest = require('firebase-functions-test')(
  settings,
  serviceAccountKeyPath
)

const testFunction = firebaseFunctions.https.onRequest(
  async (request, response) => {
    try {
      console.log('logged')

      await firebaseAdmin
        .firestore()
        .doc('tests/test')
        .set({ foo: 'bar' })

      console.log('never logged')

      return response.send()
  }
)

describe('testFunction()', () => {
  afterAll(() => {
    firebaseFunctionsTest.cleanup()
  })

  it('calls send', async () => {
    const request = {}
    const send = jest.fn()
    const response = {
      send,
    }

    try {
      await testFunction(request, response)
    } catch (err) {
      console.log(err)
    }

    expect(send).toBeCalled()
  })
})

Steps to reproduce

  1. Run the test case either with jest or firebase emulators:exec 'jest'

Expected behavior

Test should pass

Actual behavior

Test doesn't pass and no error is logged.

@garrettg123
Copy link
Author

Talk about support for a paid product :P

@laurenzlong
Copy link
Contributor

Sorry for the late response! This is still an experimental package (that's why the version number starts with 0) But that said, waiting multiple months is still not right, so apologies for that.

Looking at your code, you have

    try {
      console.log('logged')

      await firebaseAdmin
        .firestore()
        .doc('tests/test')
        .set({ foo: 'bar' })

      console.log('never logged')
      return response.send()
  }

You have a try but not a catch so if there were any errors, they wouldn't be logged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants