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

如何為 Jasmine 間諜的多個調用提供不同的返回值

How to have different return values for multiple calls on a Jasmine spy(如何為 Jasmine 間諜的多個調用提供不同的返回值)
本文介紹了如何為 Jasmine 間諜的多個調用提供不同的返回值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

假設我在監視這樣的方法:

Say I'm spying on a method like this:

spyOn(util, "foo").andReturn(true);

被測函數多次調用util.foo.

是否可以讓間諜在第一次調用時返回 true,但第二次返回 false?還是有其他方法可以解決這個問題?

Is it possible to have the spy return true the first time it's called, but return false the second time? Or is there a different way to go about this?

推薦答案

你可以使用spy.and.returnValues(如 Jasmine 2.4).

You can use spy.and.returnValues (as Jasmine 2.4).

例如

describe("A spy, when configured to fake a series of return values", function() {
  beforeEach(function() {
    spyOn(util, "foo").and.returnValues(true, false);
  });

  it("when called multiple times returns the requested values in order", function() {
    expect(util.foo()).toBeTruthy();
    expect(util.foo()).toBeFalsy();
    expect(util.foo()).toBeUndefined();
  });
});

有一點你必須注意,還有一個函數會類似地拼寫returnValue而沒有s,如果你使用它,jasmine不會警告你.

There is some thing you must be careful about, there is another function will similar spell returnValue without s, if you use that, jasmine will not warn you.

這篇關于如何為 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屋-程序員軟件開發技術
What do jasmine runs and waitsFor actually do?(jasmine 運行和等待實際上是做什么的?)
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 - 如何監視函數中的函數調用?)
主站蜘蛛池模板: 91精品一区 | 99re视频在线免费观看 | 蜜月aⅴ免费一区二区三区 99re在线视频 | 鸳鸯谱在线观看高清 | 奇色影视| 成人av一区二区亚洲精 | 日本在线视频一区二区 | 91爱爱·com| 精品亚洲一区二区三区 | 自拍视频网站 | 日日操夜夜操视频 | 日本黄色高清视频 | 日韩不卡视频在线观看 | 日日碰狠狠躁久久躁婷婷 | 欧洲视频一区二区 | 欧美日韩亚洲视频 | 国产婷婷综合 | 日本精品一区二区三区视频 | 国产福利在线看 | 成人在线视频观看 | 一区二区在线 | 青青青伊人 | 97免费视频在线观看 | 极品销魂美女一区二区 | 欧美一区二区三区日韩 | xxxcom在线观看 | 请别相信他免费喜剧电影在线观看 | 精品在线一区 | 日韩一二区在线观看 | 日韩图区 | 在线观看中文字幕 | 欧美黑人狂野猛交老妇 | 特级黄一级播放 | 亚洲精品在线免费看 | 一区二区在线看 | 欧美日日 | 三a毛片 | 2022国产精品 | 国产精品免费一区二区三区四区 | 国产精品毛片无码 | 中国大陆高清aⅴ毛片 |