Skip to content

Commit

Permalink
test: remove spyMakeErrorCatchProxy mock
Browse files Browse the repository at this point in the history
  • Loading branch information
Manussakis committed Oct 27, 2023
1 parent 3395513 commit 835cb7a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
14 changes: 4 additions & 10 deletions packages/core/src/react/hooks/__tests__/useFetchSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { SettingsProvider } from '../../provider';
import { useFetchSearch } from '../useFetchSearch';
import { setHeadlessConfig } from '../../../utils';
import * as useFetchModule from '../useFetch';
import * as utils from '../util';

describe('useFetchSearch', () => {
const wrapper = ({ children }) => {
Expand Down Expand Up @@ -41,27 +40,22 @@ describe('useFetchSearch', () => {
isLoading: false,
isValidating: false,
});
const spyMakeErrorCatchProxy = jest.spyOn(utils, 'makeErrorCatchProxy').mockReturnValue({});
const { result } = renderHook(() => useFetchSearch({}), {
wrapper,
});

await waitFor(() => {
expect(spyUseFetch).toHaveBeenCalledTimes(1);
expect(spyMakeErrorCatchProxy).toHaveBeenCalledTimes(3);
expect(result.current.error).toBe('Not found');
expect(result.current.loading).toBe(false);
expect(result.current.loading).toBe(true);
expect(() => result.current.data).not.toThrow();
expect(result.current.data).toStrictEqual({
posts: {},
pageInfo: {},
queriedObject: {},
});
expect(() => result.current.data?.posts[0].title).toThrow();
expect(() => result.current.data?.pageInfo[0].title).toThrow();
expect(() => result.current.data?.queriedObject[0].title).toThrow();
expect(result.current.isMainQuery).toBe(true);
});

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

it('fetches data properly', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/react/hooks/useFetchSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function useFetchSearch<
pageInfo: makeErrorCatchProxy<PageInfo>('pageInfo'),
queriedObject: makeErrorCatchProxy<QueriedObject>('queriedObject'),
};
return { error, loading: false, data: fakeData, isMainQuery };
return { error, loading: !data, data: fakeData, isMainQuery };
}

const { result, pageInfo, queriedObject } = data;
Expand Down

0 comments on commit 835cb7a

Please sign in to comment.