jest mocking
This commit is contained in:
33
src/container/list/__tests__/index.test.tsx
Normal file
33
src/container/list/__tests__/index.test.tsx
Normal 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();
|
||||
});
|
||||
});
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user