簡體   English   中英

jasmine中的條件測試用例

[英]Conditional test case in jasmine

我正在寫 Jasmine。 我希望當網站的響應正常時(網站上傳 - 待處理 200)。

在規范中運行它的(測試用例),當站點無法加載該站點時,它的(測試用例)將不會運行。

我在所有 function 之前檢查了來自站點的響應。

現在,如果響應(保存在全局變量中)為真,我會在每一個做出不同的事情時檢查條件

我怎樣才能像以前一樣在全球樂趣中做到這一點?

 let response; describe('', ()=>{ beforeAll (async () => { //this function return the statusCode of http request response= await sendQuery('Http://...'); }) beforeEach(async(), =>{ }); it('', async()=> { if (response = 200){ //do somsing 1... } it('', async()=> { if (response = 200){ //do somsing 2... } it('', async()=> { if (response = 200){ //do somsing 3... } v it('', async()=> { if (response = 200){ //do somsing 4... } it('', async()=> { if (response = 200){ //do somsing 5... } it('', async()=> { if (response = 200){ //do somsing 6... }

在你的配置中這樣的東西

async onPrepare() {

global.response = await sendQuery('Http://...');
    if (global.response !== 200) {
      throw new Error(`Status is ${response}`); // may not be needed actually, but I'll leave it
      await browser.close();
      await process.exit(1);
    }
}

global.response將在您的規范中可用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM