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

47 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-08-10 06:35:07 -07:00
import { __stub } from 'soapbox/api';
2022-08-10 11:02:29 -07:00
import { queryClient, renderHook, waitFor } from 'soapbox/jest/test-helpers';
2022-08-10 06:35:07 -07:00
import useTrends from '../trends';
describe('useTrends', () => {
2022-08-10 11:02:29 -07:00
beforeEach(() => {
queryClient.clear();
});
2022-08-10 07:34:12 -07:00
describe('with a successful query', () => {
2022-08-10 06:35:07 -07:00
beforeEach(() => {
__stub((mock) => {
mock.onGet('/api/v1/trends')
.reply(200, [
{ name: '#golf', url: 'https://example.com' },
{ name: '#tennis', url: 'https://example.com' },
]);
});
});
it('is successful', async() => {
const { result } = renderHook(() => useTrends());
await waitFor(() => expect(result.current.isFetching).toBe(false));
expect(result.current.data?.length).toBe(2);
});
});
2022-08-10 07:34:12 -07:00
describe('with an unsuccessful query', () => {
2022-08-10 06:35:07 -07:00
beforeEach(() => {
__stub((mock) => {
mock.onGet('/api/v1/trends').networkError();
});
});
it('is successful', async() => {
const { result } = renderHook(() => useTrends());
await waitFor(() => expect(result.current.isFetching).toBe(false));
expect(result.current.error).toBeDefined();
});
});
});