bigbuffet-rw/app/soapbox/queries/__tests__/carousels.test.ts

46 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-08-08 12:53:21 -07:00
import { renderHook } from '@testing-library/react-hooks';
import { mock, queryWrapper, waitFor } from 'soapbox/jest/test-helpers';
import useCarouselAvatars from '../carousels';
describe('useCarouselAvatars', () => {
describe('with a successul query', () => {
beforeEach(() => {
mock.onGet('/api/v1/truth/carousels/avatars')
.reply(200, [
{ account_id: '1', acct: 'a', account_avatar: 'https://example.com/some.jpg' },
{ account_id: '2', acct: 'b', account_avatar: 'https://example.com/some.jpg' },
{ account_id: '3', acct: 'c', account_avatar: 'https://example.com/some.jpg' },
{ account_id: '4', acct: 'd', account_avatar: 'https://example.com/some.jpg' },
]);
});
it('is successful', async() => {
const { result } = renderHook(() => useCarouselAvatars(), {
wrapper: queryWrapper,
});
await waitFor(() => expect(result.current.isFetching).toBe(false));
expect(result.current.data?.length).toBe(4);
});
});
describe('with an unsuccessul query', () => {
beforeEach(() => {
mock.onGet('/api/v1/truth/carousels/avatars').networkError();
});
it('is successful', async() => {
const { result } = renderHook(() => useCarouselAvatars(), {
wrapper: queryWrapper,
});
await waitFor(() => expect(result.current.isFetching).toBe(false));
expect(result.current.error).toBeDefined();
});
});
});