Skip to content

Commit 427aa4f

Browse files
committed
add test
1 parent 80b68c4 commit 427aa4f

File tree

1 file changed

+34
-0
lines changed
  • typescript-sdk/packages/client/src/transform/__tests__

1 file changed

+34
-0
lines changed

typescript-sdk/packages/client/src/transform/__tests__/http.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,40 @@ describe("transformHttpEventStream", () => {
5454
expect(receivedEvents).toEqual([mockBaseEvent]);
5555
});
5656

57+
test("should emit RUN_ERROR and complete on AbortError without erroring", () => {
58+
const mockHttpSource = new Subject<HttpEvent>();
59+
const receivedEvents: BaseEvent[] = [];
60+
let completed = false;
61+
let receivedError: unknown = undefined;
62+
63+
const result$ = transformHttpEventStream(mockHttpSource);
64+
result$.subscribe({
65+
next: (event) => receivedEvents.push(event),
66+
error: (err) => {
67+
receivedError = err;
68+
},
69+
complete: () => {
70+
completed = true;
71+
},
72+
});
73+
74+
mockHttpSource.next({
75+
type: HttpEventType.HEADERS,
76+
status: 200,
77+
headers: new Headers([["content-type", "text/event-stream"]]),
78+
});
79+
80+
const abortError = { name: "AbortError" } as DOMException;
81+
mockHttpSource.error(abortError);
82+
83+
expect(receivedEvents).toHaveLength(1);
84+
expect(receivedEvents[0].type).toBe(EventType.RUN_ERROR);
85+
const runErrorEvent = receivedEvents[0] as any;
86+
expect(runErrorEvent.rawEvent).toBe(abortError);
87+
expect(completed).toBe(true);
88+
expect(receivedError).toBeUndefined();
89+
});
90+
5791
test("should handle parseProtoStream errors", (done) => {
5892
// Given
5993
const mockHttpSource = new Subject<HttpEvent>();

0 commit comments

Comments
 (0)