-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathuseFetchContexts.test.ts
More file actions
35 lines (28 loc) · 1.09 KB
/
useFetchContexts.test.ts
File metadata and controls
35 lines (28 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { renderHook } from '@testing-library/react-hooks';
import * as hooks from './useFetchContexts';
const baseUrl = '/base';
const dataMock: Promise<any> = Promise.resolve([
'anomaly_detection.anomaly_rate',
'anomaly_detection.anomaly_rates',
'anomaly_detection.detector_events',
]);
describe('useFetchContexts', () => {
it('return correct data', async () => {
jest.spyOn(hooks, 'getContexts').mockImplementation(() => dataMock);
const { result, waitFor } = renderHook(() => hooks.useFetchContexts(baseUrl));
await result.current.fetchContexts('spaceId', 'roomId', -900, 0);
await waitFor(() => result.current.contexts.length > 0);
expect(result.current.contexts).toBeDefined();
expect(result.current.contexts).toEqual([
{ value: 'anomaly_detection.anomaly_rate', label: 'anomaly_detection.anomaly_rate' },
{
value: 'anomaly_detection.anomaly_rates',
label: 'anomaly_detection.anomaly_rates',
},
{
value: 'anomaly_detection.detector_events',
label: 'anomaly_detection.detector_events',
},
]);
});
});