Skip to content

Commit a218ae8

Browse files
committed
test: add test case to fix-request-body for text/plain
1 parent 13a55f1 commit a218ae8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/unit/fix-request-body.spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ describe('fixRequestBody', () => {
5757
expect(proxyRequest.write).toHaveBeenCalled();
5858
});
5959

60+
it('should write when body is not empty and Content-Type is text/plain', () => {
61+
const proxyRequest = fakeProxyRequest();
62+
proxyRequest.setHeader('content-type', 'text/plain; charset=utf-8');
63+
64+
jest.spyOn(proxyRequest, 'setHeader');
65+
jest.spyOn(proxyRequest, 'write');
66+
67+
fixRequestBody(proxyRequest, createRequestWithBody('some string'));
68+
69+
const expectedBody = 'some string';
70+
expect(proxyRequest.setHeader).toHaveBeenCalledWith('Content-Length', expectedBody.length);
71+
expect(proxyRequest.write).toHaveBeenCalledWith(expectedBody);
72+
});
73+
6074
it('should write when body is not empty and Content-Type is application/json', () => {
6175
const proxyRequest = fakeProxyRequest();
6276
proxyRequest.setHeader('content-type', 'application/json; charset=utf-8');

0 commit comments

Comments
 (0)