How to use the mock-socket.SocketIO function in mock-socket

To help you get started, we’ve selected a few mock-socket examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github t2t2 / vue-syncers-feathers / test / helpers / mock-socket.js View on Github external
import {createMessageEvent} from 'mock-socket/src/event-factory'
import cloneDeepWith from 'lodash/cloneDeepWith'

export class Server extends BaseServer {
	// SocketIO sends server (this) as first arg to connection & connect events, this fixes it
	dispatchEvent(event, ...customArguments) {
		if (customArguments[0] && customArguments[0] === this) {
			customArguments.shift()
		}
		return super.dispatchEvent(event, ...customArguments)
	}
}

// SocketIO class isn't exposed
const serverInstance = new Server('dummy')
const instance = new BaseSocketIOConstructor('dummy')
const BaseSocketIO = Object.getPrototypeOf(instance).constructor
instance.on('connect', () => {
	instance.close()
	serverInstance.close()
})
// GG

function cloneCustomiser(arg) {
	if (typeof arg === 'function') {
		return function (...args) {
			args = cloneDeepWith(args, cloneCustomiser)
			return arg(...args)
		}
	}
	return undefined
}

mock-socket

Javascript mocking library for websockets and socket.io

MIT
Latest version published 1 year ago

Package Health Score

63 / 100
Full package analysis