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

Can't use beforeEach mocha hooks #20

Open
armonge opened this issue Mar 30, 2018 · 0 comments
Open

Can't use beforeEach mocha hooks #20

armonge opened this issue Mar 30, 2018 · 0 comments

Comments

@armonge
Copy link

armonge commented Mar 30, 2018

Due to the way the conversation is executed mocha hooks like beforeEach are not actually executed before tests run

For example in the following code the UserStorage class has get and put methods that make requests to DynamoDB. I would like to mock those methods using simple mock

const User = require('../services/User');
const UserStorage = require('../services/UserStorage');
const simple = require('simple-mock');
const conversation = require('alexa-conversation');
const app = require('../skill'); // your Alexa skill's main file.

describe('Launch', () => {
  const opts = { // those will be used to generate the requests to your skill
    name: 'Set name',
    appId: 'your-app-id',
    app,
  };

  beforeEach(() => {
    simple.mock(UserStorage.prototype, 'get')
      .resolveWith(new User());

    simple.mock(UserStorage.prototype, 'put')
      .resolveWith();
  });

  afterEach(() => {
    simple.restore();
  });

  // initialize the conversation
  conversation(opts)
    .userSays('LaunchIntent') // trigger the first Intent
    .ssmlResponse
    .shouldMatch(/Welcome to Quizduell/)
    .shouldContain('What should be your Game name?')

    .userSays('NameIntent', { name: 'andres' })
    .ssmlResponse
    .shouldContain('I am not quite sure if I\nunderstood correctly. Is it andres?')

    .userSays('AMAZON.YesIntent')
    .ssmlResponse
    .shouldContain('All right, let\'s go. Ask me your questions or start a new game')

    .end();
});
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

1 participant