diff --git a/src/index.js b/src/index.js index 3f565b8..a2c2efb 100644 --- a/src/index.js +++ b/src/index.js @@ -196,7 +196,7 @@ export default (function create(/** @type {Options} */ defaults) { const fetchFunc = options.fetch || fetch; return fetchFunc(url, { - method: _method || options.method, + method: (_method || options.method || 'get').toUpperCase(), body: data, headers: deepMerge(options.headers, customHeaders, true), credentials: options.withCredentials ? 'include' : 'same-origin' diff --git a/test/index.test.js b/test/index.test.js index cab5374..c2160fe 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -87,7 +87,7 @@ describe('redaxios', () => { expect(window.fetch).toHaveBeenCalledWith( 'http://foo/bar', jasmine.objectContaining({ - method: 'get', + method: 'GET', headers: {}, body: undefined }) @@ -112,7 +112,7 @@ describe('redaxios', () => { expect(window.fetch).toHaveBeenCalledWith( '/foo/bar', jasmine.objectContaining({ - method: 'get', + method: 'GET', headers: {}, body: undefined }) @@ -203,7 +203,25 @@ describe('redaxios', () => { expect(fetchMock).toHaveBeenCalledWith( '/foo', jasmine.objectContaining({ - method: 'post', + method: 'POST', + headers: { + 'content-type': 'application/json' + }, + body: '{"hello":"world"}' + }) + ); + expect(res.status).toEqual(200); + expect(res.data).toEqual('yep'); + }); + + it('should issue PATCH requests (with JSON body)', async () => { + const res = await axios.patch('/foo', { + hello: 'world' + }); + expect(fetchMock).toHaveBeenCalledWith( + '/foo', + jasmine.objectContaining({ + method: 'PATCH', headers: { 'content-type': 'application/json' }, @@ -235,7 +253,7 @@ describe('redaxios', () => { expect(fetchMock).toHaveBeenCalledWith( '/foo', jasmine.objectContaining({ - method: 'post', + method: 'POST', headers: { 'content-type': 'multipart/form-data' },