Skip to content

Commit fa3ca6e

Browse files
committed
test: add unit test for accepting axios params
Signed-off-by: Dustin Popp <[email protected]>
1 parent 7d3881f commit fa3ca6e

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/unit/request-wrapper.test.js

+37
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,43 @@ describe('sendRequest', () => {
227227
expect(mockAxiosInstance.mock.calls).toHaveLength(1);
228228
});
229229

230+
it('should include any specified axios request options', async () => {
231+
const parameters = {
232+
defaultOptions: {
233+
body: 'post=body',
234+
formData: '',
235+
qs: {},
236+
method: 'POST',
237+
url: 'https://example.ibm.com/v1',
238+
headers: {
239+
'test-header': 'test-header-value',
240+
},
241+
responseType: 'buffer',
242+
axiosOptions: {
243+
signal: 'mock',
244+
},
245+
},
246+
};
247+
248+
mockAxiosInstance.mockResolvedValue(axiosResolveValue);
249+
250+
const res = await requestWrapperInstance.sendRequest(parameters);
251+
// assert results
252+
expect(mockAxiosInstance.mock.calls[0][0].data).toEqual('post=body');
253+
expect(mockAxiosInstance.mock.calls[0][0].url).toEqual('https://example.ibm.com/v1');
254+
expect(mockAxiosInstance.mock.calls[0][0].headers).toEqual({
255+
'Accept-Encoding': 'gzip',
256+
'test-header': 'test-header-value',
257+
});
258+
expect(mockAxiosInstance.mock.calls[0][0].method).toEqual(parameters.defaultOptions.method);
259+
expect(mockAxiosInstance.mock.calls[0][0].responseType).toEqual(
260+
parameters.defaultOptions.responseType
261+
);
262+
expect(mockAxiosInstance.mock.calls[0][0].signal).toEqual('mock');
263+
expect(res).toEqual(expectedResult);
264+
expect(mockAxiosInstance.mock.calls).toHaveLength(1);
265+
});
266+
230267
it('sendRequest should strip trailing slashes', async () => {
231268
const parameters = {
232269
defaultOptions: {

0 commit comments

Comments
 (0)