jest mocking

This commit is contained in:
grinikita
2025-01-18 12:24:04 +03:00
parent c7668aaff9
commit 19c0ef2882
11 changed files with 118 additions and 26 deletions

View File

@@ -0,0 +1,33 @@
import React from 'react';
import { describe, expect, test } from '@jest/globals';
import { render, screen } from '@testing-library/react';
import ListPage from '../index';
import { TestWrapper } from '../../../__tests__/test-wrapper';
import { mockGetList, spyedGetList } from '../../../__tests__/mocks/api/list/get-list';
describe('ListPage', () => {
test('renders', async () => {
const mockedGetList = mockGetList();
render(<ListPage />, {
wrapper: TestWrapper
});
expect(screen.getByText('List Page New')).toBeInTheDocument();
expect(await screen.findByText('1: title - description')).toBeInTheDocument();
expect(mockedGetList).toHaveBeenCalled();
});
test('Отображается ошибка', async () => {
spyedGetList.mockRejectedValueOnce({
message: 'В доступе отказано'
});
render(<ListPage />, {
wrapper: TestWrapper
});
expect(await screen.findByText('Произошла ошибка')).toBeInTheDocument();
});
});

View File

@@ -1,10 +1,12 @@
import React from 'react';
import { RouterProvider } from 'react-router-dom';
import { router } from './router';
import { store } from '../../store';
import { setupStore } from '../../store';
import { Provider } from 'react-redux';
import { useKeycloak } from './keycloak';
const store = setupStore();
const Main = (): React.ReactElement | string => {
const { isLoading } = useKeycloak();