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

如何為 Jasmine 間諜的多個調(diào)用提供不同的返回值

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

問題描述

限時送ChatGPT賬號..

假設(shè)我在監(jiān)視這樣的方法:

Say I'm spying on a method like this:

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

被測函數(shù)多次調(diào)用util.foo.

是否可以讓間諜在第一次調(diào)用時返回 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();
  });
});

有一點(diǎn)你必須注意,還有一個函數(shù)會類似地拼寫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.

這篇關(guān)于如何為 Jasmine 間諜的多個調(diào)用提供不同的返回值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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ù)
What do jasmine runs and waitsFor actually do?(jasmine 運(yùn)行和等待實(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)用?)
主站蜘蛛池模板: 在线观看免费av网站 | 国产精品免费看 | 免费看a| 国产九九av| 在线观看av中文字幕 | 99pao成人国产永久免费视频 | 欧美在线一级 | 国产999精品久久久久久绿帽 | 欧美aaaaa | 国产一区不卡 | 欧美午夜精品 | 国产在线观看一区二区三区 | 伊人啪啪网 | 国产美女视频黄a视频免费 国产精品福利视频 | 一级欧美视频 | 91精品国产乱码久久久久久久久 | 日韩电影在线一区 | 日韩成人在线免费观看 | 亚洲精品一区二区网址 | 自拍偷拍亚洲一区 | 黄色日本片 | 91激情视频 | 国产精品电影网 | 在线观看国产三级 | 中国黄色在线视频 | 国产日韩欧美电影 | 久久亚洲欧美日韩精品专区 | 91在线精品视频 | 青久草视频 | 成人国产免费观看 | 欧美性生活网 | 中文字幕精品视频在线观看 | 国产1区2区 | 免费福利视频一区二区三区 | 国产精品日韩欧美一区二区 | 亚洲欧美国产毛片在线 | 国产国产精品久久久久 | 情侣黄网站免费看 | 97人澡人人添人人爽欧美 | 欧美精品久久久久久久久久 | 久热电影|