0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

jestで関数ごとではなく、どこかしたらでthrow Errorの発生を予測した場合

Posted at

const Function = require('../function');
const config = require('../config.js');

同期

describe('Timeout error', () => {
  const timeOutms = 60000;

  it('will be timeout', async () => {
    const function = new Function(config.function);
    let bThrow = false;

    try {
      await function.main();
    } catch (e) {
      if (e.message.indexOf('timeout') >= 0) bThrow = true;
    }
    expect(bThrow).toBe(true);
  }, timeOutms);
});

EventEmitterを利用している場合

describe('Timeout error', () => {
  const timeOutms = 60000;

  it('will be timeout', (done) => {
    function onError(data) {
      try {
        expect(data.error.message.indexOf('timeout')).toBeGreaterThanOrEqual(0);
        done();
      } catch (error) {
        done(error);
      }
    }
    const function = new Function(config.function);
    function.main(input);
    function.once('error', onError);
  }, timeOutms);
});
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?