javascript 茉莉花是否应该按照声明的顺序或随机顺序执行规范?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30051693/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 11:34:31  来源:igfitidea点击:

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

javascriptunit-testingjasminekarma-jasmine

提问by Jeremy Danyow

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.

感谢@PWKad 指出当测试超过 10 次时会发生这种情况。

采纳答案by user1559679

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.

是的,Jasmine 按顺序执行规范(它)。从 2.3.0 到 2.3.3 存在超过 10 个规范的问题。我在 2.3.3 中遇到了同样的问题,该问题已在 2.3.4 中修复。

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

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.3.4 代替了 2.3.3,我的 15 次测试终于通过了。

回答by Anton

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.

目前 (v2.x) Jasmine 按照定义的顺序运行测试。但是,有一个新的(2015 年 10 月)选项可以以随机顺序运行规范,默认情况下仍处于关闭状态。根据项目所有者的说法,在 Jasmine 3.x 中它将被转换为默认值。

References:

参考: