Files
meanTorrent/modules/core/tests/client/socket.io.client.service.tests.js
Mikael Korpela f44c9bce71 fix(eslint): Inconsistent spacing before function parentheses (#1844)
Defines `space-before-function-paren` eslint rule and changes files accordingly.
2017-08-14 23:50:33 +03:00

44 lines
725 B
JavaScript

(function () {
'use strict';
/* Creates a mock of socket.io for the browser.
* Functionality of the service is tested through
* the chat controller tests.
*/
var ngInjector = angular.injector(['ng']),
$window = ngInjector.get('$window');
var mock = function () {
var io = {
cbs: {},
connect: connect,
emit: emit,
on: on,
removeListener: removeListener
};
connect();
return io;
function connect() {
io.socket = {};
}
function emit(msg, data) {
io.cbs[msg](data);
}
function on(msg, cb) {
io.cbs[msg] = cb;
}
function removeListener(msg) {
delete io.cbs[msg];
}
};
$window.io = mock;
}());