Unit Testing with jovo-platform-web

unit-testing
google-assistant
amazon-alexa

#1

Is it possible to run Alexa & Google unit tests in a Web App Project?

I’m getting weird errors for my unit tests.

Cannot read property 'audio' of undefined

However, I’m only using .audio in vue website code (no use of audio in assistant code).

Is there something I am missing?

Unit Test Code:

'use strict';

const { App } = require('jovo-framework');
const { Alexa } = require('jovo-platform-alexa');

for (const p of [new Alexa()]) {
    const testSuite = p.makeTestSuite();

    describe(`PLATFORM: ${p.constructor.name} INTENTS` , () => {
        test('should return a welcome message and ask for the name at "LAUNCH"', async () => {
            const conversation = testSuite.conversation();

            const launchRequest = await testSuite.requestBuilder.launch();
            const responseLaunchRequest = await conversation.send(launchRequest);

            expect(
                responseLaunchRequest.isAsk('Hello Sweets! How are you feeling today?')
            ).toBe(true);

        });
    });
}

app.js code

LAUNCH() {
    console.log("IS WEB APP: " + this.isWebApp())
    if (this.isAlexaSkill()) {
      this.ask(
        `Hello Sweets! How are you feeling today?`
      ).followUpState('EmotionState');
    } else {
      this.ask(
        `Hello Sweets! How are you feeling today?`
      ).followUpState('EmotionState');
      if (this.$webApp) {
        console.log("WEB APP")
        console.log(this.$webApp)
        const emotions = getRandomEmotions();
        this.$webApp.showQuickReplies(emotions);
      }
    }
  },

Error Message:

I’m not sure, is there something I am missing?


#2

Testing is not fully supported for WebApp projects. And the error message indicates a bug.

Here’s a workaround until the fix is published:

app.js

if (!process.env.JEST_WORKER_ID) {
    app.use(new WebPlatform())
}

This will add the WebPlatform only outside of unit tests.