Skip to content

Commit

Permalink
add additional test
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky committed Dec 31, 2022
1 parent 0ea5fef commit 6feb537
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions packages/browser/src/lib/__tests__/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,30 @@ const getGlobalMock = jest.mocked(getGlobal)
describe(fetch, () => {
const testFetchArgs = ['http://foo.com', {}] as const

it('should call native fetch if available', async () => {
const nativeFetchSpy = jest.fn()
getGlobalMock.mockReturnValue({ ...window, fetch: nativeFetchSpy })
it('should call native fetch if available', () => {
const nativeFetchMock = jest.fn()
getGlobalMock.mockReturnValue({ ...window, fetch: nativeFetchMock })
void fetch(...testFetchArgs)
expect(nativeFetchSpy).toBeCalledWith(...testFetchArgs)
expect(nativeFetchMock).toBeCalledWith(...testFetchArgs)
expect(unfetchMock).not.toBeCalled()
})
it('should fall back to unfetch', async () => {
it('should fall back to unfetch in non-browserlike environment', () => {
getGlobalMock.mockReturnValue(null)
void fetch(...testFetchArgs)
expect(unfetchMock).toBeCalledWith(...testFetchArgs)
})
it('should fall back to unfetch if fetch is unsupported', () => {
getGlobalMock.mockReturnValue({} as typeof globalThis)
void fetch(...testFetchArgs)
expect(unfetchMock).toBeCalledWith(...testFetchArgs)
})
it('should fall back to unfetch if fetch is unsupported', () => {
getGlobalMock.mockReturnValue({
...window,
fetch: undefined,
} as any)

void fetch(...testFetchArgs)
expect(unfetchMock).toBeCalledWith(...testFetchArgs)
})
})

0 comments on commit 6feb537

Please sign in to comment.