42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { __stub } from 'soapbox/api';
|
|
import { renderHook, waitFor } from 'soapbox/jest/test-helpers';
|
|
|
|
import useTrends from '../trends';
|
|
|
|
describe('useTrends', () => {
|
|
describe('with a successul query', () => {
|
|
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);
|
|
});
|
|
});
|
|
|
|
describe('with an unsuccessul query', () => {
|
|
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();
|
|
});
|
|
});
|
|
});
|