Fakultas Ilmu Komputer UI

index.test.tsx 920 Bytes
Newer Older
1
2
3
4
import React from 'react';
import { render, waitFor } from '@testing-library/react-native';
import axios from 'axios';

5
import ClientDietRecommendationForAdmin from '.';
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { mockDietRecommendation } from '__mocks__/dietRecommendation';

jest.mock('axios');
const mockAxios = axios as jest.Mocked<typeof axios>;

jest.mock('@react-navigation/native', () => {
  return {
    useRoute: () => ({
      params: {
        id: 1,
      },
    }),
  };
});

21
describe('ClientDietRecommendationForAdmin', () => {
22
23
24
25
26
27
28
29
  const retrievedietRecommendationByIdApi = () =>
    Promise.resolve({
      status: 200,
      data: mockDietRecommendation,
    });

  it('fetches data from backend and renders correctly', async () => {
    mockAxios.request.mockImplementationOnce(retrievedietRecommendationByIdApi);
30
    render(<ClientDietRecommendationForAdmin />);
31
32
33
    await waitFor(() => expect(mockAxios.request).toBeCalled());
  });
});