[Docs] Unit Testing for Voice Apps


#1

To make sure your Alexa Skills and Google Actions are robust, we highly recommend testing. Learn how to implement unit tests for your voice apps built with Jovo.


This is a companion discussion topic for the original entry at https://www.jovo.tech/docs/unit-testing

#2

You can only use i18n keys:

const conversation = testSuite.conversation({ locale: 'keys-only' });

if you don’t also include in your config.js:

    i18n: {
        fallbackLng: 'en-US'
    }

#3

Ah thank you. Yes, this makes sense and should be added to the docs


#4

I wrote a unit test for a case where the skill is accessing the jovo context via jovo.$user.$context.prev[0].request.state. In the test db file I can see that the $context.prev object is set correctly:

However: the test fails because prev is undefined. I can see in the debugger that at this moment the $user.$context Object only contains the constructor. Is there something I am doing wrong or is the tmp fileDB not set correctly for testing?
Thanks again =)
André


#5

Hey, in my unit tests I used conversation.$user.$data.key = value; to set user data. This works fine for Alexa. However in the unit test for GoogleAssistant the user data is undefined. Here is a link to a repository, where I edited the HelloWorld template in order to reproduce the error: https://github.com/LeonardMF/jovo-sample-test


#6

Hey @LeonardMF thank you for the sample code. It made it really easy to reproduce.

I found a bug in the GoogleActionRequest class. It’s fixed and I will publish the fix later this week.


#7

Thank you, @AlexSwe . Just let me know, when it is published :slightly_smiling_face:


#8

Done. (random text to get to the 20 characters.)


#9

Can the unit test httpsOptions.url config be set to lambda/cloud function url ?
Tried and got this error in unit test:
Response for preflight has invalid HTTP status code 500
and this at the cloud function: ERR_NO_MATCHING_PLATFORM

The cloud function works fine outside of unit test.
The unit test works fine with default localhost webhook.

conversation = testSuite.conversation({
    httpOptions: {
      method: "POST",
      url: "https://xxxxxxxx.cloudfunctions.net/myCloudFunction",
    },
  });

#10

Hi @vguruv, thank you. This doesn’t work right now, interesting suggestion though!

Would be great if you could create a feature request in an issue here: https://github.com/jovotech/jovo-framework/issues