* #708 apply strictier linting rules and fix simple eslint bugs * #708 fix eslint errors relate to promise * #708 fix eslint import/no-extraneous-dependencies * #708 fix eslint errors of react-hook * #708 enable eslint check for typescript --------- Co-authored-by: lethemanh <lethemanh@lethemanhs-MacBook-Pro.local>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
export function setupWebsocket() {
|
||||
const originalWebSocket = global.WebSocket;
|
||||
const webSocketInstances: any[] = [];
|
||||
const originalWebSocket = global.WebSocket
|
||||
const webSocketInstances: any[] = []
|
||||
const mockWebSocket = jest.fn().mockImplementation((url: string) => {
|
||||
const ws = {
|
||||
url,
|
||||
@@ -9,27 +9,27 @@ export function setupWebsocket() {
|
||||
removeEventListener: jest.fn(),
|
||||
send: jest.fn(),
|
||||
close: jest.fn(),
|
||||
_listeners: {} as Record<string, Function[]>,
|
||||
};
|
||||
_listeners: {} as Record<string, Function[]>
|
||||
}
|
||||
|
||||
ws.addEventListener.mockImplementation((event, handler) => {
|
||||
ws._listeners[event] ??= [];
|
||||
ws._listeners[event].push(handler);
|
||||
});
|
||||
ws._listeners[event] ??= []
|
||||
ws._listeners[event].push(handler)
|
||||
})
|
||||
|
||||
ws.removeEventListener.mockImplementation((event, handler) => {
|
||||
ws._listeners[event] =
|
||||
ws._listeners[event]?.filter((h) => h !== handler) ?? [];
|
||||
});
|
||||
ws._listeners[event]?.filter(h => h !== handler) ?? []
|
||||
})
|
||||
|
||||
webSocketInstances.push(ws);
|
||||
return ws;
|
||||
});
|
||||
webSocketInstances.push(ws)
|
||||
return ws
|
||||
})
|
||||
|
||||
global.WebSocket = mockWebSocket as any;
|
||||
global.WebSocket = mockWebSocket as any
|
||||
const cleanup = () => {
|
||||
global.WebSocket = originalWebSocket;
|
||||
webSocketInstances.length = 0;
|
||||
};
|
||||
return { webSocketInstances, mockWebSocket, cleanup };
|
||||
global.WebSocket = originalWebSocket
|
||||
webSocketInstances.length = 0
|
||||
}
|
||||
return { webSocketInstances, mockWebSocket, cleanup }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user