![](/img/trans.png)
[英]AngularJS & Protractor & Jasmine - global variable for all specs
[英]How to use global variable in specs using protractor and Jasmine
我正在嘗試達到一些全局變量。 例如:
var date = 0;
it('must set a value', function(){
date = 5;
});
it('must compare', function(){
expect(date).toBe(5);
});
it
阻止不應該相互依賴。 首先,因為執行是異步的,這將導致您發生意外的行為。 其次,因為單元測試應該易於准備和獨立...因此,當一個單元失敗時,您就知道實際失敗的原因(即您無需查看其他單元塊)
我不確定您要使用代碼實現什么,但是在我看來,您想要的是類似於以下代碼的東西:
describe('MyTestSpec', function () {
var date = 0;
beforeEach(function () {
//Using beforeEach will actually assume that date will be set to 5
//before the execution of your it-block.
date = 5;
});
it('check if date is 5', function () {
expect(date).toBe(5);
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.