这里有一些使用STOMP协议编写的Web Socket代码。
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) {
};
我找到这篇帖子,但它需要实际连接服务器才能进行测试, Unit testing Node.js and WebSockets (Socket.io)
我们如何使用Jasmine测试这个问题呢? 寻找一种伪造WebSocket服务器并触发事件(连接、断开等)的方法。 我会非常感激任何示例或有用链接。