diff --git a/src/lib/fetch-handler.js b/src/lib/fetch-handler.js index d07f9542..40a63b6f 100755 --- a/src/lib/fetch-handler.js +++ b/src/lib/fetch-handler.js @@ -31,11 +31,11 @@ const patchNativeFetchForSafari = (nativeFetch) => { return nativeFetch; } // It seems the code is working on Safari thus patch native fetch to avoid the error. - return async (request) => { + return async (request, ...args) => { const { method } = request; if (!['POST', 'PUT', 'PATCH'].includes(method)) { // No patch is required in this case - return nativeFetch(request); + return nativeFetch(request, ...args); } const body = await request.clone().text(); const { diff --git a/test/specs/config/safari.test.js b/test/specs/config/safari.test.js new file mode 100644 index 00000000..63e989c3 --- /dev/null +++ b/test/specs/config/safari.test.js @@ -0,0 +1,41 @@ +const chai = require('chai'); +const expect = chai.expect; + +const { fetchMock, theGlobal } = testGlobals; + +describe('Safari override', () => { + beforeEach(() => { + fetchMock.createInstance(); + }); + + it('passes all GET arguments to next function when not under Safari', async () => { + theGlobal.fetch = async (...args) => { + expect(args[0]).to.equal('http://mocked.com/'); + expect(args[1]).to.deep.equal({ method: 'GET' }); + return { status: 202 }; + }; + fetchMock.spy('http://mocked.com'); + const res = await fetchMock.fetchHandler('http://mocked.com', { + method: 'GET', + }); + expect(res.status).to.equal(202); + fetchMock.restore(); + delete theGlobal.fetch; + }); + + it('passes all GET arguments to next function under Safari', async () => { + theGlobal.navigator = { vendor: 'Apple Computer, Inc.' }; + theGlobal.fetch = async (...args) => { + expect(args[0]).to.equal('http://mocked.com/'); + expect(args[1]).to.deep.equal({ method: 'GET' }); + return { status: 202 }; + }; + fetchMock.spy('http://mocked.com'); + const res = await fetchMock.fetchHandler('http://mocked.com', { + method: 'GET', + }); + expect(res.status).to.equal(202); + fetchMock.restore(); + delete theGlobal.fetch; + }); +});