forked from wheresrhys/fetch-mock
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: Ensure all arguments are passed to base fetch function
This is not a great fix; it ignores that method is only inspected when it's in the first fetch() parameter, and it glosses over the fact that the navigator object, for historical reasons, is very constrained in the responses it gives (which is why the code snagged jsdom in the first place). It does, however, solve my immediate need of getting fetch-mock to interoperate with jsdom. Fixes wheresrhys#608
- Loading branch information
Brian Crowell
committed
May 15, 2021
1 parent
4b54e6d
commit 6154fe6
Showing
2 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}); | ||
}); |