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

使用 Jasmine 測(cè)試 Web 套接字

Testing Web Sockets with Jasmine(使用 Jasmine 測(cè)試 Web 套接字)
本文介紹了使用 Jasmine 測(cè)試 Web 套接字的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

這是一些使用 stomp 協(xié)議為 web-socket 編寫(xiě)的代碼.

Here is some code that has been written for web-socket using stomp protocol.

function WS(url) {
    var ws = new SockJS('/notifications');

    this.client = Stomp.over(ws),

    this.client.connect('', '', function() {
        console.log('Connected');
    }, function(error) {
        console.log('STOMP protocol error: ', error.headers.message);
    });
}

WS.prototype.disconnect = function() {
};

WS.prototype.subscribe = function() {
};

WS.prototype.unSubscribe = function() {
};

WS.prototype.send = function(msg) {
};

我找到了這篇文章,但它需要實(shí)際連接到服務(wù)器,單元測(cè)試Node.js和WebSockets (Socket.io)

I found this post but it requires actual connection to server, Unit testing Node.js and WebSockets (Socket.io)

我們?nèi)绾问褂?Jasmine 進(jìn)行測(cè)試.尋找一種偽造網(wǎng)絡(luò)套接字服務(wù)器和觸發(fā)事件(連接、斷開(kāi)連接等)的方法.我將不勝感激任何示例或有用的鏈接.

How do we test this using Jasmine. Looking for a way to fake web-socket server and fire events (connect, disconnect etc). I'll appreciate any example or useful link.

推薦答案

只需模擬函數(shù)的所有依賴項(xiàng),因此在您的情況下,這將是 SockJSStomp.over.

Just mock all your dependencies of your function, so in your case this will be SockJS and Stomp.over.

var wsSpy = jasmine.createSpy();
spyOn(window, 'SockJs').andReturn(wsSpy);

var clientSpy = jasmine.createSpy();
spyOne(Stomp, 'over').andReturn(clientSpy)

運(yùn)行腳本后,您可以測(cè)試他們被調(diào)用的間諜.要運(yùn)行回調(diào)函數(shù),您可以使用 mostRecentCall.args 找到它們并在測(cè)試中調(diào)用它們:

After running your script you can test on the spies that they was called. To run the callback functions you can use mostRecentCall.args to find them and call them in the test:

var successCallBack = clientSpy.mostRecentCall.args[2];
successCallBack();

var errorCallBack = clientSpy.mostRecentCall.args[3];
errorCallBack();

這篇關(guān)于使用 Jasmine 測(cè)試 Web 套接字的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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 測(cè)試裝置加載?) - IT屋-程序員軟件開(kāi)發(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(如何提供模擬文件來(lái)更改 lt;input type=filegt; 的事件用于單元測(cè)試)
How to unit test a chained method using Jasmine(如何使用 Jasmine 對(duì)鏈?zhǔn)椒椒ㄟM(jìn)行單元測(cè)試)
How do I inject $rootScope into an AngularJS unit test?(如何將 $rootScope 注入 AngularJS 單元測(cè)試?)
Jasmine - How to spy on a function call within a function?(Jasmine - 如何監(jiān)視函數(shù)中的函數(shù)調(diào)用?)
主站蜘蛛池模板: 久久se精品一区精品二区 | 九九久久国产精品 | 久久精品中文字幕 | 国产精品久久久久久久久免费软件 | 成人欧美一区二区三区在线播放 | 久久精品69 | 国产xxxx岁13xxxxhd | 日日操操 | 国产电影一区二区三区爱妃记 | 男人的天堂久久 | 亚洲一区中文 | 精品国产三级 | 精品国产乱码久久久久久丨区2区 | 欧美亚洲一区二区三区 | 黄色av大片 | 亚洲精品一区二区在线观看 | 国产精品久久精品 | 精国产品一区二区三区四季综 | 日韩中文字幕一区 | 久久艹免费视频 | 欧美日韩精品一区二区三区四区 | 久久久久久免费精品一区二区三区 | 久久久久久久久99 | 午夜小视频免费观看 | 日韩精品在线播放 | 日韩精品一区二区三区视频播放 | 丝袜 亚洲 另类 欧美 综合 | 欧美日韩精品一区二区三区四区 | 91久久久久 | 日本成人在线观看网站 | 中文字幕日韩欧美一区二区三区 | 国产免费又色又爽又黄在线观看 | 欧美一区二区三区精品免费 | 99视频免费 | 成人深夜福利 | 亚洲欧美日韩在线一区二区 | 一区二区免费 | 亚洲欧美日韩在线一区二区 | 日本中文字幕在线视频 | 狠狠操狠狠色 | 成人精品一区 |