久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

jasmine 運(yùn)行和等待實(shí)際上是做什么的?

What do jasmine runs and waitsFor actually do?(jasmine 運(yùn)行和等待實(shí)際上是做什么的?)
本文介紹了jasmine 運(yùn)行和等待實(shí)際上是做什么的?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號..

我使用 jasmine 運(yùn)行并等待測試異步操作.一切正常,但我不太確定幕后發(fā)生了什么.

I use jasmine runs and wait to test asynchronous operations. Everything works fine but I'm not quite sure what goes on behind the scenes.

jasmine 文檔說明了以下示例,我在其中添加了三個(gè)日志語句.

The jasmine documentation states the following example to which I added three log statement.

describe("Asynchronous specs", function() {
  var value, flag;

  it("should support async execution of test preparation and exepectations", function() {

    runs(function() {
      flag = false;
      value = 0;

      setTimeout(function() {
        flag = true;
      }, 500);
    });

    waitsFor(function() {
      value++;
      if(flag) {
          console.log("A");
      }
      return flag;
    }, "The Value should be incremented", 750);

    console.log("B");

    runs(function() {
      console.log("C");
      expect(value).toBeGreaterThan(0);
    });
  });
});

});

第一個(gè) runswaitsFor 對我來說非常清楚.Runs 啟動異步操作,waitsFor 等待條件.

The first runs and waitsFor are perfectly clear to me. Runs starts an asynchronous operation and waitsFor waits for a condition.

但是我不明白為什么第二個(gè) runs 直到 waitsFor 完成才開始.waitsFor 不是阻塞調(diào)用.

However I do not understand why the second runs does not start until the waitsFor is finished. The waitsFor is not a blocking call.

我的猜測是 waitsFor 會隱式阻止任何后續(xù)的 runs 調(diào)用,直到它完成.是這樣嗎?

My guess is that waitsFor implicitly blocks any following runs call until it is finished. Is this so?

我的證據(jù)是 console.log 語句輸出:

My evidence is that the console.log statements output:

B A C

但如果 waitsFor 真的會阻塞它應(yīng)該是

But if waitsFor would really block it should be

A B C

推薦答案

waitsFor 會阻塞,直到它等待的條件滿足或超時(shí).

waitsFor does block until the conditions it's waiting for are met or it times out.

來自 jasmine 文檔:waitsFor() 提供了一個(gè)更好的接口,用于暫停你的規(guī)范,直到完成其他一些工作.Jasmine 將等到提供的函數(shù)返回 true,然后再繼續(xù)下一個(gè)塊.".

From the jasmine docs: "waitsFor() provides a better interface for pausing your spec until some other work has completed. Jasmine will wait until the provided function returns true before continuing with the next block.".

鏈接的文檔也有一個(gè)更清晰的示例或 waitsFor.

The linked docs also have a slightly clearer example or waitsFor.

編輯:啊,我明白你的意思了.waitsFor 不會阻塞未包含在 runswaitsFor 等中的 JS.

EDIT: Ah I see what you mean now. waitsFor won't block JS that isn't wrapped in runs, waitsFor, ect.

jasmine 正在做的是獲取通過 runswaitsFor 傳遞給它的函數(shù),如果 jasmine 當(dāng)前沒有等待,它會立即執(zhí)行該函數(shù).如果它正在等待,它在等待完成之前不會調(diào)用它.

What jasmine is doing is taking the function passed to it via runs or waitsFor and if jasmine is not currently waiting, it executes the function immediately. If it is waiting, it doesn't call it until it's finished waiting.

這不會停止 console.log,因?yàn)樗驯粋鬟f給 jasmine,因此 jasmine 無法阻止它立即執(zhí)行.

That doesn't stop the console.log as it's been passed to jasmine so jasmine can't prevent it from being executed straight away.

這篇關(guān)于jasmine 運(yùn)行和等待實(shí)際上是做什么的?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 認(rèn)為文檔“準(zhǔn)備好之前,如何讓我的 jasmine 測試裝置加載?) - IT屋-程序員軟件開發(fā)技術(shù)
How to provide mock files to change event of lt;input type=#39;file#39;gt; for unit testing(如何提供模擬文件來更改 lt;input type=filegt; 的事件用于單元測試)
How to unit test a chained method using Jasmine(如何使用 Jasmine 對鏈?zhǔn)椒椒ㄟM(jìn)行單元測試)
How do I inject $rootScope into an AngularJS unit test?(如何將 $rootScope 注入 AngularJS 單元測試?)
Jasmine - How to spy on a function call within a function?(Jasmine - 如何監(jiān)視函數(shù)中的函數(shù)調(diào)用?)
jasmine test fails with undefined is not a function(evaluating $browser.$$checkUrlChange())(茉莉花測試失敗,未定義不是函數(shù)(評估 $browser.$$checkUrlChange()))
主站蜘蛛池模板: 成人免费激情视频 | 欧产日产国产精品国产 | 亚洲三区在线观看 | 欧洲精品在线观看 | 日日干天天操 | 国产精品久久久久久婷婷天堂 | 国产精品一区二区三区久久 | 欧美乱操 | 精品久久中文字幕 | 请别相信他免费喜剧电影在线观看 | 亚洲一区在线日韩在线深爱 | 国产综合久久 | 欧美在线色 | 福利二区 | 亚洲一区二区免费电影 | 久久久成人免费一区二区 | 亚洲欧美一区二区三区1000 | 久草新在线 | 久久网一区二区三区 | 午夜影院| 欧美黄色免费网站 | 亚洲精品国产偷自在线观看 | 欧美日韩一区在线播放 | 在线观看日韩 | 91日韩 | 欧美亚洲在线视频 | 欧美一级三级在线观看 | 久久毛片| 国产在线观看一区二区三区 | 天天弄| 九九精品久久久 | 波多野结衣在线观看一区二区三区 | 国产欧美精品一区二区三区 | 56pao在线| 美女拍拍拍网站 | 欧美精品91 | 亚洲精品乱码久久久久久按摩观 | 亚洲一区中文字幕 | 日韩电影免费在线观看中文字幕 | 91在线中文字幕 | 日韩成人av在线 |