web-dev-qa-db-ja.com

ジャスミンは、宣言された順序またはランダムな順序で仕様を実行することになっていますか?

最後の仕様のコメントを外します。すべての地獄が崩れ落ちる...なぜ?

describe('test', function() {
  var index = 1;

  it('test 1', function() {
    expect(index).toBe(1);
    index++;
  });

  it('test 2', function() {
    expect(index).toBe(2);
    index++;
  });

  it('test 3', function() {
    expect(index).toBe(3);
    index++;
  });

  it('test 4', function() {
    expect(index).toBe(4);
    index++;
  });

  it('test 5', function() {
    expect(index).toBe(5);
    index++;
  });

  it('test 6', function() {
    expect(index).toBe(6);
    index++;
  });

  it('test 7', function() {
    expect(index).toBe(7);
    index++;
  });

  it('test 8', function() {
    expect(index).toBe(8);
    index++;
  });

  it('test 9', function() {
    expect(index).toBe(9);
    index++;
  });

  it('test 10', function() {
    expect(index).toBe(10);
    index++;
  });

  // it('test 11', function() {
  //   expect(index).toBe(11);
  //   index++;
  // });

});

@PWKadの指摘に感謝します。これは、10を超えるテストがある場合に発生します。

22
Jeremy Danyow

はい、Jasmineは仕様(それ)を順番に実行します。 2.3.0から2.3.3まで、10を超える仕様の問題がありました。 2.3.3で同じ問題が発生しました。この問題は2.3.4で修正されています。

https://github.com/jasmine/jasmine/issues/85

2.3.3の代わりに2.3.4を使用しただけで、15のテストに合格しました。

17
user1559679

現在(v2.x)Jasmineは定義された順序でテストを実行します。ただし、仕様をランダムな順序で実行するための新しい(2015年10月)オプションがあり、デフォルトではまだオフになっています。プロジェクトオーナーによると、Jasmine 3.xではデフォルトに変換されます。

参照:

11
Anton