Is jasmine supposed to execute specs in the order they are declared or in a random order?

亡梦爱人 提交于 2019-12-18 05:28:26

问题


un-comment the last spec. All hell breaks loose... why?

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++;
  // });

});

thanks to @PWKad for pointing out this happens when there are more than 10 tests.


回答1:


Yes, Jasmine executes the specs (it) in order. There was an issue from 2.3.0 to 2.3.3 with more than 10 specs. I hit the same issue in 2.3.3, the issue is fixed in 2.3.4.

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

I just used 2.3.4 in place of 2.3.3 and my 15 tests finally passed.




回答2:


Currently (v2.x) Jasmine runs tests in the order they are defined. However, there is a new (Oct 2015) option to run specs in a random order, which is still off by default. According to the project owner, in Jasmine 3.x it will be converted to be the default.

References:

  • Feature Discussion
  • User Story in the Project Tracker
  • Feature Pull Request


来源:https://stackoverflow.com/questions/30051693/is-jasmine-supposed-to-execute-specs-in-the-order-they-are-declared-or-in-a-rand

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!