From 0dd32edd86f70de06778dda245fa90c4df811916 Mon Sep 17 00:00:00 2001 From: KetineniM Date: Thu, 6 Apr 2023 14:19:54 +0530 Subject: [PATCH] JEST/RTL test cases for useLoadSubInstances --- src/hooks/useLoadSubInstances.test.js | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/hooks/useLoadSubInstances.test.js 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([]); + }); +});