本文介紹了我們如何在 Jasmine 中以編程方式清除間諜?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我們如何以編程方式清除 jasmine 測試套件中的間諜?謝謝.
How do we clear the spy in a jasmine test suite programmatically? Thanks.
beforeEach(function() {
spyOn($, "ajax").andCallFake(function(params){
})
})
it("should do something", function() {
//I want to override the spy on ajax here and do it a little differently
})
推薦答案
我不確定這是否是個好主意,但您可以簡單地將函數上的 isSpy
標志設置為 false:
I'm not sure if its a good idea but you can simply set the isSpy
flag on the function to false:
describe('test', function() {
var a = {b: function() {
}};
beforeEach(function() {
spyOn(a, 'b').andCallFake(function(params) {
return 'spy1';
})
})
it('should return spy1', function() {
expect(a.b()).toEqual('spy1');
})
it('should return spy2', function() {
a.b.isSpy = false;
spyOn(a, 'b').andCallFake(function(params) {
return 'spy2';
})
expect(a.b()).toEqual('spy2');
})
})
但是,如果您需要間諜的其他行為,則為這種情況創建一個新套件可能是一個更好的主意.
But maybe its a better idea to create a new suite for this case where you need an other behavior from your spy.
這篇關于我們如何在 Jasmine 中以編程方式清除間諜?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!