Skip to content

Commit

Permalink
test: should report close event to disconnect callback
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Jan 12, 2021
1 parent b6f5f5f commit e4fb7eb
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/tests/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1383,3 +1383,26 @@ describe('Subscribe', () => {
client.ws.terminate();
});
});

describe('Disconnect', () => {
it('should report close code and reason to disconnect callback', async (done) => {
const { url, waitForConnect } = await startTServer({
onDisconnect: (_ctx, code, reason) => {
expect(code).toBe(4321);
expect(reason).toBe('Byebye');
done();
},
});

const client = await createTClient(url);

client.ws.send(
stringifyMessage<MessageType.ConnectionInit>({
type: MessageType.ConnectionInit,
}),
);
await waitForConnect();

client.ws.close(4321, 'Byebye');
});
});

0 comments on commit e4fb7eb

Please sign in to comment.