![](/img/trans.png)
[英]Jasmine how pass specs that run in any order that depend on a closure variable
[英]Is jasmine supposed to execute specs in the order they are declared or in a random order?
取消注釋最后一個規范。 所有的地獄都崩潰了……為什么?
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 次時會發生這種情況。
是的,Jasmine 按順序執行規范(它)。 從 2.3.0 到 2.3.3 存在超過 10 個規范的問題。 我在 2.3.3 中遇到了同樣的問題,該問題已在 2.3.4 中修復。
https://github.com/jasmine/jasmine/issues/850
我只是用 2.3.4 代替了 2.3.3,我的 15 次測試終於通過了。
目前 (v2.x) Jasmine 按照定義的順序運行測試。 但是,有一個新的(2015 年 10 月)選項可以以隨機順序運行規范,默認情況下仍處於關閉狀態。 根據項目所有者的說法,在 Jasmine 3.x 中它將被轉換為默認值。
參考:
我現在是 2021 年,事實上,通過npx jasmine init
的默認設置似乎默認設置了隨機測試順序。
當然不是大多數開發人員所期望的。 (不是我所期望的!)
要按聲明的順序運行,請進入您的spec/support/jasmine.json
並設置:
"random": false
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.