Skip to content

Commit

Permalink
test: add test case for TransformStream error
Browse files Browse the repository at this point in the history
  • Loading branch information
YumoImer committed Dec 4, 2024
1 parent d8bb0df commit aca796b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions components/x-request/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,24 @@ describe('XRequest Class', () => {
new Error(`The response content-type: ${contentType} is not support!`),
);
});

test('should handle TransformStream errors', async () => {
const errorTransform = new TransformStream({
transform() {
throw new Error('Transform error');
},
});

mockedXFetch.mockResolvedValueOnce({
headers: {
get: jest.fn().mockReturnValue('application/x-ndjson'),
},
body: mockNdJsonReadableStream(),
});

await request.create(params, callbacks, errorTransform).catch(() => {});
expect(callbacks.onError).toHaveBeenCalledWith(new Error('Transform error'));
expect(callbacks.onSuccess).not.toHaveBeenCalled();
expect(callbacks.onUpdate).not.toHaveBeenCalled();
});
});

0 comments on commit aca796b

Please sign in to comment.