-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #761 from wheresrhys/rhys/error-handling
Rhys/error handling
- Loading branch information
Showing
6 changed files
with
119 additions
and
40 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
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
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,44 @@ | ||
import { describe, expect, it, beforeAll } from 'vitest'; | ||
import fetchMock from '../FetchMock'; | ||
describe('Spec compliance', () => { | ||
// NOTE: these are not exhaustive, but feel like a sensible, reasonably easy to implement subset | ||
// https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch#exceptions | ||
describe('exceptions', () => { | ||
beforeAll(() => fetchMock.catch()); | ||
it('reject on invalid header name', async () => { | ||
await expect( | ||
fetchMock.fetchHandler('http://a.com', { | ||
headers: { | ||
'has space': 'ok', | ||
}, | ||
}), | ||
).rejects.toThrow(new TypeError('Invalid name')); | ||
}); | ||
it('reject on url containing credentials', async () => { | ||
await expect( | ||
fetchMock.fetchHandler('http://user:[email protected]'), | ||
).rejects.toThrow( | ||
new TypeError( | ||
'Request cannot be constructed from a URL that includes credentials: http://user:[email protected]/', | ||
), | ||
); | ||
}); | ||
it('reject if the request method is GET or HEAD and the body is non-null.', async () => { | ||
await expect( | ||
fetchMock.fetchHandler('http://a.com', { body: 'a' }), | ||
).rejects.toThrow( | ||
new TypeError('Request with GET/HEAD method cannot have body.'), | ||
); | ||
await expect( | ||
fetchMock.fetchHandler('http://a.com', { body: 'a', method: 'GET' }), | ||
).rejects.toThrow( | ||
new TypeError('Request with GET/HEAD method cannot have body.'), | ||
); | ||
await expect( | ||
fetchMock.fetchHandler('http://a.com', { body: 'a', method: 'HEAD' }), | ||
).rejects.toThrow( | ||
new TypeError('Request with GET/HEAD method cannot have body.'), | ||
); | ||
}); | ||
}); | ||
}); |
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