Skip to content

Commit 856058a

Browse files
codewithkenzofelixweinberger
authored andcommitted
fix: use optional chaining for tsgo type checker compatibility
1 parent ce6f778 commit 856058a

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

packages/server/test/server/streamableHttp.test.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,9 @@ describe('Zod v4', () => {
808808

809809
expect(response.status).toBe(400);
810810
expect(errors.length).toBeGreaterThan(0);
811-
expect(errors[0]!.message).toContain('Parse error');
811+
const error = errors[0];
812+
expect(error).toBeDefined();
813+
expect(error?.message).toContain('Parse error');
812814
});
813815

814816
it('should call onerror for invalid JSON-RPC message', async () => {
@@ -825,7 +827,9 @@ describe('Zod v4', () => {
825827

826828
expect(response.status).toBe(400);
827829
expect(errors.length).toBeGreaterThan(0);
828-
expect(errors[0]!.message).toContain('Parse error');
830+
const error = errors[0];
831+
expect(error).toBeDefined();
832+
expect(error?.message).toContain('Parse error');
829833
});
830834

831835
it('should call onerror for missing Accept header on POST', async () => {
@@ -835,7 +839,9 @@ describe('Zod v4', () => {
835839

836840
expect(response.status).toBe(406);
837841
expect(errors.length).toBeGreaterThan(0);
838-
expect(errors[0]!.message).toContain('Not Acceptable');
842+
const error = errors[0];
843+
expect(error).toBeDefined();
844+
expect(error?.message).toContain('Not Acceptable');
839845
});
840846

841847
it('should call onerror for unsupported Content-Type', async () => {
@@ -852,7 +858,9 @@ describe('Zod v4', () => {
852858

853859
expect(response.status).toBe(415);
854860
expect(errors.length).toBeGreaterThan(0);
855-
expect(errors[0]!.message).toContain('Unsupported Media Type');
861+
const error = errors[0];
862+
expect(error).toBeDefined();
863+
expect(error?.message).toContain('Unsupported Media Type');
856864
});
857865

858866
it('should call onerror for server not initialized', async () => {
@@ -862,7 +870,9 @@ describe('Zod v4', () => {
862870

863871
expect(response.status).toBe(400);
864872
expect(errors.length).toBeGreaterThan(0);
865-
expect(errors[0]!.message).toContain('Server not initialized');
873+
const error = errors[0];
874+
expect(error).toBeDefined();
875+
expect(error?.message).toContain('Server not initialized');
866876
});
867877

868878
it('should call onerror for invalid session ID', async () => {
@@ -874,7 +884,9 @@ describe('Zod v4', () => {
874884

875885
expect(response.status).toBe(404);
876886
expect(errors.length).toBeGreaterThan(0);
877-
expect(errors[0]!.message).toContain('Session not found');
887+
const error = errors[0];
888+
expect(error).toBeDefined();
889+
expect(error?.message).toContain('Session not found');
878890
});
879891

880892
it('should call onerror for re-initialization attempt', async () => {
@@ -886,7 +898,9 @@ describe('Zod v4', () => {
886898

887899
expect(response.status).toBe(400);
888900
expect(errors.length).toBeGreaterThan(0);
889-
expect(errors[0]!.message).toContain('Server already initialized');
901+
const error = errors[0];
902+
expect(error).toBeDefined();
903+
expect(error?.message).toContain('Server already initialized');
890904
});
891905

892906
it('should call onerror for GET without Accept header', async () => {
@@ -898,7 +912,9 @@ describe('Zod v4', () => {
898912

899913
expect(response.status).toBe(406);
900914
expect(errors.length).toBeGreaterThan(0);
901-
expect(errors[0]!.message).toContain('Not Acceptable');
915+
const error = errors[0];
916+
expect(error).toBeDefined();
917+
expect(error?.message).toContain('Not Acceptable');
902918
});
903919

904920
it('should call onerror for concurrent SSE streams', async () => {
@@ -912,7 +928,9 @@ describe('Zod v4', () => {
912928

913929
expect(response2.status).toBe(409);
914930
expect(errors.length).toBeGreaterThan(0);
915-
expect(errors[0]!.message).toContain('Conflict');
931+
const error = errors[0];
932+
expect(error).toBeDefined();
933+
expect(error?.message).toContain('Conflict');
916934
});
917935

918936
it('should call onerror for unsupported protocol version', async () => {
@@ -933,7 +951,9 @@ describe('Zod v4', () => {
933951

934952
expect(response.status).toBe(400);
935953
expect(errors.length).toBeGreaterThan(0);
936-
expect(errors[0]!.message).toContain('Unsupported protocol version');
954+
const error = errors[0];
955+
expect(error).toBeDefined();
956+
expect(error?.message).toContain('Unsupported protocol version');
937957
});
938958
});
939959
});

0 commit comments

Comments
 (0)