-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bfb6f96
commit 5a5f239
Showing
1 changed file
with
51 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { | ||
QueryClient, | ||
QueryClientProvider, | ||
} from 'react-query'; | ||
|
||
import { useOkapiKy } from '@folio/stripes/core'; | ||
|
||
import { getAddresses } from '../../utils'; | ||
import { useAddresses } from './useAddresses'; | ||
|
||
jest.mock('../../utils', () => ({ | ||
getAddresses: jest.fn(), | ||
})); | ||
|
||
const queryClient = new QueryClient(); | ||
const wrapper = ({ children }) => ( | ||
<QueryClientProvider client={queryClient}> | ||
{children} | ||
</QueryClientProvider> | ||
); | ||
|
||
describe('useAddresses', () => { | ||
const mockGet = jest.fn(); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
|
||
useOkapiKy.mockReturnValue({ | ||
get: mockGet, | ||
}); | ||
}); | ||
|
||
it('should return addresses and totalRecords', async () => { | ||
const configs = [{ value: 'address1' }, { value: 'address2' }]; | ||
const totalRecords = 2; | ||
|
||
mockGet.mockReturnValue({ | ||
json: jest.fn().mockResolvedValue({ configs, totalRecords }), | ||
}); | ||
|
||
getAddresses.mockReturnValue(['address1', 'address2']); | ||
|
||
const { result, waitFor } = renderHook(() => useAddresses(), { wrapper }); | ||
|
||
await waitFor(() => !result.current.isLoading); | ||
|
||
expect(result.current.addresses).toEqual(['address1', 'address2']); | ||
expect(result.current.totalRecords).toBe(2); | ||
}); | ||
}); |