Skip to content

Commit

Permalink
JEST/RTL test cases for useLoadSubInstances
Browse files Browse the repository at this point in the history
  • Loading branch information
KetineniM committed Apr 6, 2023
1 parent 595f7dc commit 0dd32ed
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/hooks/useLoadSubInstances.test.js
Original file line number Diff line number Diff line change
@@ -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 }) => (
<QueryClientProvider client={queryClient}>
{children}
</QueryClientProvider>
);

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([]);
});
});

0 comments on commit 0dd32ed

Please sign in to comment.