Need help understanding unittests

18 views
Skip to first unread message

Daniel Watrous

unread,
Nov 30, 2018, 5:35:34 AM11/30/18
to Firebase Google Group
I have spent a few days looking over the only example I can find about unittesting: https://firebase.google.com/docs/functions/unit-testing#testing_http_functions

I followed this to the following file, but I really don't understand the highlighted lines of code


I have a test right now that should be failing, but it's passing, so I know the assertion isn't being called. I'm not sure what would call "redirect" or when that might be something else or what values/names would make sense there. I know my function is getting called, but it's a dialogflow directive, like "conv.ask(...)" or "conv.close(...)". I know those return HTTP responses when deployed, but I'm not sure if they do when called by the unittests. 

Any ideas to help me with this?


Abe Haskins (Firebase)

unread,
Nov 30, 2018, 1:27:47 PM11/30/18
to Firebase Google Group
Hey Daniel!

In my personal opinion, that sample isn't very practical for testing HTTPS onRequest handlers IRL. All our HTTPS handlers are wrappers around Express.js which means that mocking out a complete response is not trivial and results in issues like what you're seeing.

My preference is to test the function via a dedicated ExpressJS testing tool like supertest. You can see a code snippet there to see how it works. Let me know if you have any issues!

All the best,
abe

Daniel Watrous

unread,
Dec 1, 2018, 4:09:16 AM12/1/18
to Firebase Google Group
I think what I'm really trying to figure out is what "conv.ask("something");" actually does. Maybe this is out of scope for firebase, but I'm trying to test a dialogflow/actions-on-google app, and I can't figure out how to do it.
Reply all
Reply to author
Forward
0 new messages