All files / botbuilder-unit/spec timeoutSpec.js

73.08% Statements 19/26
100% Branches 0/0
60% Functions 6/10
73.08% Lines 19/26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 551x 1x 1x 1x 1x   1x 3x 3x 3x 3x                           3x   1x 1x                   1x 1x           1x 1x     1x 1x          
const botFactory = require('./lib/botFactory');
const unit = require('../');
describe('Timeout test suite', function () {
  let script = require('./scripts/timeout');
  let bot = null;
 
  beforeEach((done) => {
    try {
      jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
      bot = botFactory();
      bot.dialog('/test', [
        (session, args, next) => {
          session.send('Test dialog welcomes you!')
          next();
        },
        (session) => {
          setTimeout(() => {
            session.endDialog('End of test dialog')
          }, 2000)
        }
      ])
    } catch (e) {
      fail(e)
    }
    done();
  });
  it('Should support `timeout` field, will fail if timeout exceeded', (done) => {
    unit(bot, script, {
      timeout: 1000,
      title: 'Should support `timeout` field, will fail if timeout exceeded'
    })
      .then(() => {
        fail('Impossible call');
        done();
      })
      .catch(done)
  });
  it('Test finishes successfully, if timeout not exceed', (done) => {
    unit(bot, script, {
      timeout: 3000,
      title: 'Test finishes successfully, if timeout not exceed'
    })
      .then(done)
      .catch((err) => {
        fail('Impossible call');
        done();
      })
  });
  it('If timeout set to zero, library will wait', (done) => {
    unit(bot, script, {
      timeout : 0,
      title: 'If timeout set to zero, library will wait'
    }).then(done);
  })
})