Skip to content

Commit

Permalink
test: useFetchAppSettings with error or no data
Browse files Browse the repository at this point in the history
  • Loading branch information
Manussakis committed Nov 14, 2023
1 parent b06f064 commit 1da956a
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/core/src/react/hooks/__tests__/useFetchAppSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { renderHook } from '@testing-library/react';
import { renderHook, waitFor } from '@testing-library/react';
import { expectTypeOf } from 'expect-type';
import { AppEntity, EndpointParams } from '../../../data';
import { useFetchAppSettings } from '../useFetchAppSettings';
import * as useFetchModule from '../useFetch';
import { mockUseFetchErrorResponse } from '../mocks';

describe('useFetchAppSettings types', () => {
it('allows overriding types', () => {
Expand All @@ -23,4 +25,22 @@ describe('useFetchAppSettings types', () => {
| undefined
>();
});

it('handles response if has error or there is no data', async () => {
const spyUseFetch = jest
.spyOn(useFetchModule, 'useFetch')
.mockReturnValueOnce(mockUseFetchErrorResponse);
const { result } = renderHook(() => useFetchAppSettings({ includeCustomSettings: true }));

await waitFor(() => {
expect(spyUseFetch).toHaveBeenCalledTimes(1);
expect(result.current.error).toBe('Not found');
expect(result.current.loading).toBe(true);
expect(() => result.current.data).not.toThrow();
expect(() => result.current.data?.posts).toThrow();
expect(result.current.isMainQuery).toBe(true);
});

spyUseFetch.mockRestore();
});
});

0 comments on commit 1da956a

Please sign in to comment.