Fix test
This commit is contained in:
parent
afec0edc1c
commit
8d05747537
1 changed files with 21 additions and 17 deletions
|
@ -1,43 +1,47 @@
|
||||||
import { __stub } from 'soapbox/api';
|
import { __stub } from 'soapbox/api';
|
||||||
import { buildGroup } from 'soapbox/jest/factory';
|
import { buildGroup } from 'soapbox/jest/factory';
|
||||||
import { renderHook, waitFor } from 'soapbox/jest/test-helpers';
|
import { renderHook, waitFor } from 'soapbox/jest/test-helpers';
|
||||||
|
import { normalizeInstance } from 'soapbox/normalizers';
|
||||||
|
|
||||||
import { useGroups } from '../useGroups';
|
import { useGroups } from '../useGroups';
|
||||||
|
|
||||||
const group = buildGroup({ id: '1', display_name: 'soapbox' });
|
const group = buildGroup({ id: '1', display_name: 'soapbox' });
|
||||||
|
const store = {
|
||||||
|
instance: normalizeInstance({
|
||||||
|
version: '3.4.1 (compatible; TruthSocial 1.0.0+unreleased)',
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
describe('useGroups hook', () => {
|
describe('useGroups hook', () => {
|
||||||
describe('with a successful request', () => {
|
describe('with a successful request', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
__stub((mock) => {
|
__stub((mock) => {
|
||||||
mock.onGet('/api/v1/groups?q=').reply(200, [group]);
|
mock.onGet('/api/v1/groups').reply(200, [group]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is successful', async () => {
|
it('is successful', async () => {
|
||||||
const { result } = renderHook(() => useGroups());
|
const { result } = renderHook(useGroups, undefined, store);
|
||||||
|
|
||||||
console.log(result.current);
|
|
||||||
|
|
||||||
await waitFor(() => expect(result.current.isFetching).toBe(false));
|
await waitFor(() => expect(result.current.isFetching).toBe(false));
|
||||||
|
|
||||||
expect(result.current.groups.length).toHaveLength(1);
|
expect(result.current.groups).toHaveLength(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// describe('with an unsuccessful query', () => {
|
describe('with an unsuccessful query', () => {
|
||||||
// beforeEach(() => {
|
beforeEach(() => {
|
||||||
// __stub((mock) => {
|
__stub((mock) => {
|
||||||
// mock.onGet('/api/v1/groups').networkError();
|
mock.onGet('/api/v1/groups').networkError();
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// it('is has error state', async() => {
|
it('is has error state', async() => {
|
||||||
// const { result } = renderHook(() => useGroups());
|
const { result } = renderHook(useGroups, undefined, store);
|
||||||
|
|
||||||
// await waitFor(() => expect(result.current.isFetching).toBe(false));
|
await waitFor(() => expect(result.current.isFetching).toBe(false));
|
||||||
|
|
||||||
// expect(result.current.groups).toHaveLength(0);
|
expect(result.current.groups).toHaveLength(0);
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
});
|
});
|
Loading…
Reference in a new issue