LoginSignup
5
5

More than 5 years have passed since last update.

Jasmineで書く遅延処理のテスト

Last updated at Posted at 2012-08-30

waitsForの第一引数のfunctionを、timeout時間分絶えず実行し、trueが返れば続くrunsを実行。timeoutした場合はエラーを表示、という流れ。これで非同期のテストができる。

var flg = false;
it('test', function () {
    setTimeout(function () {
        flg = true;
    }, 3000);
    waitsFor(function () {
        console.log(flg); //これが繰り返し呼ばれる
        return flg;
    }, 'Timed out', 1000);

    runs(function () {
        expect(flg).toEqual(true);
    });
});

5
5
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
5
5