Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export default (function create(/** @type {Options} */ defaults) {
*/
const customHeaders = {};

if (data && typeof data === 'object') {
if (data && typeof data === 'object' && !(data instanceof FormData)) {
data = JSON.stringify(data);
customHeaders['Content-Type'] = 'application/json';
}
Expand Down
17 changes: 17 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,21 @@ describe('redaxios', () => {
expect(res.status).toEqual(200);
expect(JSON.parse(res.data)).toEqual({ hello: 'world' });
});

it('should not send content-type when data contains FormData', async () => {
const oldFetch = window.fetch;
try {
window.fetch = jasmine.createSpy('fetch').and.returnValue(Promise.resolve());
axios.post('/foo', new FormData());
expect(window.fetch).toHaveBeenCalledTimes(1);
expect(window.fetch).not.toHaveBeenCalledWith('/foo', jasmine.objectContaining({
headers: {
'content-type': 'application/json'
}
}));
}
finally {
window.fetch = oldFetch;
}
});
});