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

jasmine 運行和等待實際上是做什么的?

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

問題描述

限時送ChatGPT賬號..

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

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 文檔說明了以下示例,我在其中添加了三個日志語句.

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);
    });
  });
});

});

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

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

但是我不明白為什么第二個 runs 直到 waitsFor 完成才開始.waitsFor 不是阻塞調用.

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 會隱式阻止任何后續的 runs 調用,直到它完成.是這樣嗎?

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

我的證據是 console.log 語句輸出:

My evidence is that the console.log statements output:

B A C

但如果 waitsFor 真的會阻塞它應該是

But if waitsFor would really block it should be

A B C

推薦答案

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

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

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

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.".

鏈接的文檔也有一個更清晰的示例或 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 傳遞給它的函數,如果 jasmine 當前沒有等待,它會立即執行該函數.如果它正在等待,它在等待完成之前不會調用它.

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,因為它已被傳遞給 jasmine,因此 jasmine 無法阻止它立即執行.

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.

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

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

相關文檔推薦

How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 認為文檔“準備好之前,如何讓我的 jasmine 測試裝置加載?) - IT屋-程序員軟件開發技術
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 對鏈式方法進行單元測試)
How do I inject $rootScope into an AngularJS unit test?(如何將 $rootScope 注入 AngularJS 單元測試?)
Jasmine - How to spy on a function call within a function?(Jasmine - 如何監視函數中的函數調用?)
jasmine test fails with undefined is not a function(evaluating $browser.$$checkUrlChange())(茉莉花測試失敗,未定義不是函數(評估 $browser.$$checkUrlChange()))
主站蜘蛛池模板: 国产蜜臀| 久久久久久国产精品 | 精品久久精品 | 日韩欧美中文字幕在线视频 | 亚洲成网站 | 在线观看国产视频 | 成人精品福利 | 欧美一级黄色免费看 | 国产成人精品一区二区三区在线 | 国产亚洲精品精品国产亚洲综合 | 很很干很很日 | 欧美激情一区二区三区 | 91久久夜色精品国产网站 | 亚洲精品9999 | 一区二区免费 | 秋霞在线一区 | 亚洲欧美视频在线观看 | 五月婷婷 六月丁香 | 欧美在线观看一区 | 日韩在线 | 91福利在线观看 | 欧美激情亚洲天堂 | 亚洲欧美在线视频 | 日本成人在线播放 | 精精国产xxxx视频在线播放 | 成人欧美一区二区三区色青冈 | 91天堂网 | 日韩一区三区 | 国产成人午夜电影网 | 国产1区2区在线观看 | 中文久久 | 日韩高清国产一区在线 | 永久免费在线观看 | 91色视频在线观看 | 亚洲精品一区中文字幕乱码 | 日本三级在线视频 | 亚洲二区精品 | 欧美久久久网站 | 精品一区免费 | 国产91精品网站 | 日韩欧美一级精品久久 |