I know this topic is 3 months old, but I have found a workaround so if anyone searches for this they will have an answer.
The reason your unit test is not working is that WebSocket is not globally installed when you run it in say Jest for example.
A quick work around would be to define it globally.
// npm install ws
const globalAny: any = global; // This way we don't get an error in TypeScript saying WebSocket is not a defined property on global
globalAny.WebSocket = require('ws');
Also, it appears as though the colyseus.js client makes use of the window.local storage object. A quick polyfill you could do would look something like this
globalAny.window = {
localStorage: {
getItem: () => {},
setItem: () => {}
},
};