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

如何測試一個函數沒有被調用?

How can I test that a function has not been called?(如何測試一個函數沒有被調用?)
本文介紹了如何測試一個函數沒有被調用?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在測試路由器并且有兩個函數,我需要測試第一個函數是否被調用而第二個函數沒有.有方法 toHaveBeenCalled 但沒有方法來測試函數是否未被調用.我該如何測試?

I'm testing router and have two functions, and I need to test if first function was called and second was not. There is method toHaveBeenCalled but there is no method to test if function was not called. How can I test that?

我有這樣的代碼:

var args, controller, router;
beforeEach(function() {
    controller = {
        foo: function(name, id) {
            args = [].slice.call(arguments);
        },
        bar: function(name) {
        }
    };
    spyOn(controller, "foo").and.callThrough();
    spyOn(controller, "bar").and.callThrough();
    router = new route();
    router.match('/foo/bar/{{id}}--{{name}}', controller.foo);
    router.match('/foo/baz/{{id}}--{{name}}', controller.bar);
    router.exec('/foo/bar/10--hello');
});
it('foo route shuld be called', function() {
    expect(controller.foo).toHaveBeenCalled();
});
it('bar route shoud not be called', function() {
    // how to test if bar was not called?
});

推薦答案

使用 not 運算符:

expect(controller.bar).not.toHaveBeenCalled();

這篇關于如何測試一個函數沒有被調用?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 - 如何監視函數中的函數調用?)
主站蜘蛛池模板: 97影院2| 亚洲人免费视频 | 丁香婷婷在线视频 | 91丨九色丨国产在线 | 中文字幕免费 | 中文字幕在线电影观看 | 殴美成人在线视频 | 黄色毛片网站在线观看 | 中文字幕在线播放第一页 | www狠狠干| 中文字幕在线观 | 五月婷婷色 | 九九国产 | 日韩久久网 | www.99精品| 久久免费看 | 精品日韩一区 | 久久精品无码一区二区三区 | 国产精品国色综合久久 | 激情欧美日韩一区二区 | 美美女高清毛片视频免费观看 | 国内精品一区二区三区 | 久久综合九色综合欧美狠狠 | 久热m3u8 | 欧美日韩国产传媒 | 日韩第一页 | 91成人在线 | 99精品国产成人一区二区 | 成年人在线观看 | 视频一区在线观看 | 毛片在线看看 | 亚洲永久| 国产一区二区在线免费观看 | 九九精品在线 | 91精品国模一区二区三区 | 欧美伊人久久久久久久久影院 | 亚洲一区二区三区在线视频 | 国产一区二区久久久 | 国产精品视频一区二区三区 | 精品久久久久久久久久久 | 日韩成人免费在线视频 |