Skip to content

Commit

Permalink
fix(useFetch): respect custom fetch option (#1603)
Browse files Browse the repository at this point in the history
  • Loading branch information
wheatjs committed May 16, 2022
1 parent 0aecfe6 commit 56eb358
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/core/useFetch/index.test.ts
Expand Up @@ -52,6 +52,18 @@ describe('useFetch', () => {
})
})

test('should use custom fetch', async () => {
let count = 0
await useFetch('https://example.com/', {
fetch(input: RequestInfo, init?: RequestInit | undefined) {
count = 1
return window.fetch(input, init)
},
})

expect(count).toEqual(1)
})

test('should have an error on 400', async () => {
const { error, statusCode } = useFetch('https://example.com?status=400')

Expand Down
2 changes: 1 addition & 1 deletion packages/core/useFetch/index.ts
Expand Up @@ -205,7 +205,7 @@ export interface CreateFetchOptions {
* to include the new options
*/
function isFetchOptions(obj: object): obj is UseFetchOptions {
return containsProp(obj, 'immediate', 'refetch', 'initialData', 'timeout', 'beforeFetch', 'afterFetch', 'onFetchError')
return containsProp(obj, 'immediate', 'refetch', 'initialData', 'timeout', 'beforeFetch', 'afterFetch', 'onFetchError', 'fetch')
}

function headersToObject(headers: HeadersInit | undefined) {
Expand Down

0 comments on commit 56eb358

Please sign in to comment.