diff options
Diffstat (limited to 'web/test/connection.test.ts')
| -rw-r--r-- | web/test/connection.test.ts | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/web/test/connection.test.ts b/web/test/connection.test.ts index 27958ba..3426881 100644 --- a/web/test/connection.test.ts +++ b/web/test/connection.test.ts @@ -53,6 +53,22 @@ describe('GameConnection', () => { expect(statuses).toContain('open'); }); + // Regression: the open gate must compare against the real + // `WebSocket.OPEN` readyState (1). A wrong constant (e.g. 0 = CONNECTING) + // silently dropped every outbound frame — hello, ping, and every command + // — because the readyState check never matched, while the unit tests + // passed only because the fake mirrored the same wrong constant. + it('sends frames only when readyState is the real WebSocket.OPEN (1)', () => { + conn.connect(); + const socket = sockets.current; + // Before open the socket is CONNECTING (0): nothing may be sent. + expect(socket.sent).toHaveLength(0); + expect(socket.readyState).toBe(0); + socket.open(); // → OPEN (1) + expect(socket.readyState).toBe(1); + expect(socket.lastJson()).toEqual({ t: 'hello', v: 1 }); + }); + it('forwards update, seats, and error to their handlers', () => { const messages: string[] = []; let errorMessage: string | null = null; |
