diff --git a/src/hooks/useLoadSubInstances.test.js b/src/hooks/useLoadSubInstances.test.js new file mode 100644 index 000000000..6263046f1 --- /dev/null +++ b/src/hooks/useLoadSubInstances.test.js @@ -0,0 +1,40 @@ +import React from 'react'; +import { + QueryClient, + QueryClientProvider, +} from 'react-query'; +import { renderHook } from '@testing-library/react-hooks'; + +import '../../test/jest/__mock__'; + +import { useOkapiKy } from '@folio/stripes/core'; + +import { instances } from '../../test/fixtures'; +import useLoadSubInstances from './useLoadSubInstances'; + +const queryClient = new QueryClient(); +const wrapper = ({ children }) => ( + + {children} + +); + +describe('useLoadSubInstances', () => { + let mock; + beforeEach(() => { + mock = useOkapiKy.mockClear().mockReturnValue({ + get: () => ({ + json: () => ({ instances }), + }), + }); + }); + + afterEach(() => { + mock.mockRestore(); + }); + + it('returns an empty array when given an empty array of instance ids', () => { + const { result } = renderHook(() => useLoadSubInstances(instances.map(({ id }) => id)), { wrapper }); + expect(result.current).toEqual([]); + }); +});